TechnologiesSwiftUI

AutomaticFormStyle struct

iOSmacOStvOSwatchOSvisionOSiOS 16.0+✓ renders

The default form style.

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.

  1. 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 .automatic shorthand selects AutomaticFormStyle, as in .formStyle(.automatic) on the demo's Form. 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.

  2. Let the Form supply the content

    AutomaticFormStyle styles whatever the Form contains rather than generating layout itself. The Form here wraps a Section("Profile") holding a TextField and a Toggle, and the style decides how those rows and the section header are aligned and inset for the current platform.

  3. Group rows with Section

    Sections are the unit the style lays out: it gives each Section its header treatment and separates groups of controls visually. The Section("Profile") label becomes a context-appropriate heading, and the TextField and Toggle inside it are spaced as a related group instead of as loose, full-width rows.

  4. 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 .automatic is enough — but the conformance is what lets the type participate in the same styling mechanism as the named alternatives like .grouped and .columns.

Try it — Change .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.

AutomaticFormStyle.swift
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()
    }
}
Live preview
Profile Ada Notifications
Profile Ada Notifications
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →