One Logo Pool Ball
SwiftUI · IOS API REFERENCE

Form

struct · iOS 13.0+ · SDK 27.1

nonisolated struct Form<Content> where Content : View

A container for grouping controls used for data entry, such as in settings or inspectors. SwiftUI applies platform-appropriate styling to views contained inside a form, to group them together. Form-specific styling applies to things like buttons, toggles, labels, lists, and more. Keep in mind that these stylings may be platform-specific. For example, forms appear as grouped lists on iOS, and as aligned vertical stacks on macOS. The following example shows a simple data entry form on iOS, grouped into two sections. The supporting types (`NotifyMeAboutType` and `ProfileImageSize`) and state variables (`notifyMeAbout`, `profileImageSize`, `playNotificationSounds`, and `sendReadReceipts`) are omitted for simplicity. var body: some View { NavigationView { Form { Section(header: Text("Notifications")) { Picker("Notify Me About", selection: $notifyMeAbout) { Text("Direct Messages").tag(NotifyMeAboutType.directMessages) Text("Mentions").tag(NotifyMeAboutType.mentions) Text("Anything").tag(NotifyMeAboutType.anything) } Toggle("Play notification sounds", isOn: $playNotificationSounds) Toggle("Send read receipts", isOn: $sendReadReceipts) } Section(header: Text("User Profiles")) { Picker("Profile Image Size", selection: $profileImageSize) { Text("Large").tag(ProfileImageSize.large) Text("Medium").tag(ProfileImageSize.medium) Text("Small").tag(ProfileImageSize.small) } Button("Clear Image Cache") {} } } } } ![A form on iOS, presented as a grouped list with two sections. The first section is labeled Notifications and contains a navigation link with the label Notify Me About and the current value Direct Messages. The section also contains two toggles, Play Notification Sounds and Send Read Receipts, the first of which is set to the on position. A second section named User Profiles has a navigation link labeled Profile Image Size and the value Medium, followed by a button labeled Clear Image Cache.](SwiftUI-Form-iOS.png) On macOS, a similar form renders as a vertical stack. To adhere to macOS platform conventions, this version doesn't use sections, and uses colons at the end of its labels. It also sets the picker to use the ``PickerStyle/inline`` style, which produces radio buttons on macOS. var body: some View { Spacer() HStack { Spacer() Form { Picker("Notify Me About:", selection: $notifyMeAbout) { Text("Direct Messages").tag(NotifyMeAboutType.directMessages) Text("Mentions").tag(NotifyMeAboutType.mentions) Text("Anything").tag(NotifyMeAboutType.anything) } Toggle("Play notification sounds", isOn: $playNotificationSounds) Toggle("Send read receipts", isOn: $sendReadReceipts) Picker("Profile Image Size:", selection: $profileImageSize) { Text("Large").tag(ProfileImageSize.large) Text("Medium").tag(ProfileImageSize.medium) Text("Small").tag(ProfileImageSize.small) } .pickerStyle(.inline) Button("Clear Image Cache") {} } Spacer() } Spacer() } ![A form on iOS, presented as a vertical stack of views. At top, it shows a pop-up menu with the label label Notify Me about and the current value Direct Messages. Below this are two checkboxes, labeled Play Notification Sounds and Send Read Receipts, the first of which is set on. Below this is the label Profile Image Size with three radio buttons -- Large, Medium, and Small -- with Medium currently selected. At the bottom of the form, there is a button titled Clear Image Cache.](SwiftUI-Form-macOS.png)

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Form.init(content:)

callback cannot propagate synchronous failure

Form.body

This protocol needs associated types that cannot yet cross the bridge.

All SwiftUI types →