Navigation and Forms: Toggle in Forms

Another common form control is Toggle.

You can see it widely used in the Settings app.

struct ContentView: View {
    @State private var enabled = true
    
    var body: some View {
        Form {
            Toggle("Enable?", isOn: $enabled)
        }
    }
}

It works similarly to a TextField view, except instead of a String value passed with the text parameter, we pass a Bool value to isOn.

If you set it to true the toggle is enabled, if you set it to false it’s disabled:

Of course the user can enable or disable it by tapping on the control, and that automatically updates the variable passed to isOn.

Lessons in this unit:

0: Introduction
1: NavigationView
2: TabView
3: SF Symbols
4: Forms
5: TextField in Forms
6: ▶︎ Toggle in Forms
7: Slider in Forms
8: Stepper in Forms
9: Picker in Forms
10: DatePicker in Forms

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026