Form

cilippofilia's avatar
Published Jan 31, 2023
Contribute to Docs

The Form view displays collected data in a single column. It is the main element used inside the settings application on Apple devices or “System Settings” on other devices.

Syntax

var body: some View {
    Form {
        Subviews here
    }
}

Example

In the example below, a Form is wrapped inside a NavigationView that will display four fields:

@State private var email = ""
var body: some View {
NavigationView {
Form {
Text("This is a text")
TextField("This is a textfield", text: $email)
Button("This is a button") { }
NavigationLink("This is a navigation link", destination:EmptyView())
}
}
}
  • NavigationView is a container that’s fundamental to the display, and allows NavigationLink to properly work.
  • Text is a built-in view that display standard text.
  • The TextField view allows the user to insert contact information, type memos, and edit the content of a specific field.
  • The Button view allows users to interact with the UI and perform certain actions.
  • The NavigationLink view controls how the navigation between views is displayed to the user.

This will display the following:

Form

All contributors

Contribute to Docs

Learn SwiftUI on Codecademy