The Form container
struct SettingsView: View {
@State private var name = ""
@State private var notifications = true
@State private var theme = "Light"
var body: some View {
Form {
Section("Profile") {
TextField("Name", text: $name)
}
Section("Preferences") {
Toggle("Notifications", isOn: $notifications)
Picker("Theme", selection: $theme) {
Text("Light").tag("Light")
Text("Dark").tag("Dark")
}
}
}
}
}
Simple validation
Button("Save") { save() }
.disabled(name.isEmpty) // can't tap until valid
Tip: Two-way binding with $ means the view and your state always stay in sync automatically.