How it works
DefaultToggleStyle is the toggle style SwiftUI applies automatically when you don't specify one of your own. It resolves at runtime to the style that's idiomatic for the current context and platform — typically a switch in most layouts, and a checkbox inside forms and other containers where that reads more naturally. Reach for it when you want a Toggle to match the conventional look for where it sits, or when you need to return to that conventional appearance after a custom style was applied higher in the view hierarchy.
Conform to ToggleStyle through the default
DefaultToggleStyle is a concrete type conforming to the ToggleStyle protocol, so it can stand in anywhere a toggle style is expected. You rarely name its members directly; instead it produces the standard control body for each Toggle it governs, such as
Toggle("Wi-Fi", isOn: $wifiOn).Apply it with toggleStyle(_:)
The toggleStyle(_:) modifier sets the style for every Toggle in the subtree it's attached to. Here
.toggleStyle(DefaultToggleStyle())is placed on theForm, so bothToggle("Wi-Fi", isOn: $wifiOn)andToggle("Bluetooth", isOn: $bluetoothOn)adopt the context-appropriate appearance.Construct it with the no-argument initializer
DefaultToggleStyle has a single parameterless initializer — there are no options to configure, because the point of this style is to defer the decision to SwiftUI. Writing
DefaultToggleStyle()asks the framework to pick the right control for the surrounding context rather than pinning a fixed look.Let context decide the rendered control
Because the resolved appearance depends on where the Toggle lives, the same
DefaultToggleStyle()can render differently. Inside thisForm, the toggles bound to$wifiOnand$bluetoothOntake on the form-appropriate presentation for the platform, whereas the identical declaration outside a form may render as a plain switch.Use it to override an inherited style
Applying
.toggleStyle(DefaultToggleStyle())also restores standard behavior when an ancestor view set a different style. Attaching it at theFormre-establishes the default for the toggles within, overriding any toggle style inherited from further up the hierarchy.
.toggleStyle(DefaultToggleStyle()) to .toggleStyle(.switch) and compare how the Wi-Fi and Bluetooth rows render to see what the default resolves to in a form.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 DefaultToggleStyleDemo: View {
@State private var wifiOn = true
@State private var bluetoothOn = false
var body: some View {
Form {
Toggle("Wi-Fi", isOn: $wifiOn)
Toggle("Bluetooth", isOn: $bluetoothOn)
}
.toggleStyle(DefaultToggleStyle())
.padding()
}
}