How it works
AutomaticFormStyle is the default FormStyle that SwiftUI applies to a Form when you don't request a specific one. Rather than fixing a single appearance, it defers to the surrounding context — the platform, the enclosing container, and the current environment — to choose how labels, controls, and sections are arranged and spaced. Reach for it when you want a form that looks native everywhere without committing to .grouped or .columns, or when you need to reset a form back to system-driven layout after another style was applied higher up.
Apply it with formStyle(.automatic)
The style is attached through the
formStyle(_:)modifier, which writes a FormStyle into the environment for every Form below it. Passing the.automaticshorthand selects AutomaticFormStyle, as in.formStyle(.automatic)on the demo'sForm. Because it reads as the system default, this call is also the way to explicitly opt back into automatic behavior in a subtree where a different style is in effect.Let the Form supply the content
AutomaticFormStyle styles whatever the
Formcontains rather than generating layout itself. TheFormhere wraps aSection("Profile")holding aTextFieldand aToggle, and the style decides how those rows and the section header are aligned and inset for the current platform.Group rows with Section
Sections are the unit the style lays out: it gives each
Sectionits header treatment and separates groups of controls visually. TheSection("Profile")label becomes a context-appropriate heading, and theTextFieldandToggleinside it are spaced as a related group instead of as loose, full-width rows.Resolve through the FormStyle conformance
AutomaticFormStyle conforms to FormStyle, so SwiftUI calls its
makeBody(configuration:)to produce the rendered form from the configuration. You rarely touch this directly — using.automaticis enough — but the conformance is what lets the type participate in the same styling mechanism as the named alternatives like.groupedand.columns.
.formStyle(.automatic) to .formStyle(.grouped) and watch the same Section, TextField, and Toggle shift to inset, card-like grouping — the contrast shows what layout the automatic style was choosing for you.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct AutomaticFormStyleDemo: View {
@State private var enabled = true
@State private var name = "Ada"
var body: some View {
Form {
Section("Profile") {
TextField("Name", text: $name)
Toggle("Notifications", isOn: $enabled)
}
}
.formStyle(.automatic)
.padding()
}
}