How it works
DefaultPickerStyle resolves a picker to the standard presentation that SwiftUI chooses for the current platform and surrounding context, so you don't have to hard-code a specific look. Rather than committing to a menu, wheel, or segmented appearance, you defer that decision to the framework, which adapts the control to where it appears — a form, a toolbar, or a plain container. Reach for it when you want a picker to feel native everywhere and to track future platform conventions automatically, or when you need to undo an inherited style and fall back to the system default.
Apply it through pickerStyle(_:)
You rarely name DefaultPickerStyle directly; instead you select it by passing its shorthand to the pickerStyle(_:) modifier on a Picker. In the example,
.pickerStyle(.automatic)opts thePicker("Flavor", selection: $flavor)into the default, letting SwiftUI render whatever presentation suits the context.Use the .automatic shorthand
The static member
.automaticis the type-inferred way to ask for DefaultPickerStyle, mirroring the struct's role as the framework-chosen baseline. Passing.automaticis equivalent to requesting the default style and is the value you supply when you want SwiftUI to decide rather than dictating a concrete appearance.Bind a selection so the resolved style has state to drive
Whatever presentation DefaultPickerStyle resolves to still reads and writes the picker's bound value. Here the
selection: $flavorbinding connects to the@State private var flavorproperty, and each option supplies its identity with.tag("Vanilla"),.tag("Chocolate"), and.tag("Strawberry")so the default style knows which row is current.Let context determine the final presentation
Because DefaultPickerStyle is context-sensitive, the same
.pickerStyle(.automatic)can appear as a menu, an inline list, or a wheel depending on the enclosing container and platform. Moving thisPickerinto a Form, a navigation stack, or a toolbar changes what the default resolves to without any change to the style call itself.
.pickerStyle(.automatic) for .pickerStyle(.wheel) to pin the control to a fixed wheel, then change it back to see how DefaultPickerStyle instead lets SwiftUI pick the presentation 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 DefaultPickerStyleDemo: View {
@State private var flavor = "Vanilla"
var body: some View {
Picker("Flavor", selection: $flavor) {
Text("Vanilla").tag("Vanilla")
Text("Chocolate").tag("Chocolate")
Text("Strawberry").tag("Strawberry")
}
.pickerStyle(.automatic)
.padding()
}
}