NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Working with forms

Paul Hudson    @twostraws   

Updated for Xcode 14.2

With its firm focus on declarative user interfaces, it should be no surprise that SwiftUI gives us a fantastic mechanism for building forms – collections of user input controls designed to gather information, such as an order form or a settings screen.

Even better, several parts of SwiftUI automatically adapt to being placed inside forms, with their appearance and behavior changing so they work better alongside other groups of input controls.

If you thought that was clever, you’re going to love this: SwiftUI actually dynamically adjusts the layouts to the point where it can make whole new screens automatically for us depending on what platform your code is running on – it fully decouples the purpose of our controls from their visuals. This means we describe what we want and SwiftUI figures out the idiomatic way to make that happen on the current platform.

Tip: Forms are regular containers just like VStack, so you can switch between the two freely depending on your purpose.

Hacking with Swift is sponsored by Waldo

SPONSORED Thorough mobile testing hasn’t been efficient testing. With Waldo Sessions, it can be! Test early, test often, test directly in your browser and share the replay with your team.

Try for free today!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Similar solutions…

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 3.9/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.