How it works
AutomaticImmersionStyle is the immersion style that lets the system decide how much of a person's surroundings an immersive space replaces, rather than you fixing a level yourself. It conforms to the ImmersionStyle protocol, so you supply it through the immersionStyle(selection:in:) modifier on an ImmersiveSpace in the same way you'd supply MixedImmersionStyle, ProgressiveImmersionStyle, or FullImmersionStyle. Reach for it when you want sensible default behavior that adapts to the platform and context, or as the starting selection before the person or the app switches to a more specific style. You rarely name the type directly; you refer to its shared value through the .automatic shorthand on ImmersionStyle.
Refer to the style through the .automatic shorthand
AutomaticImmersionStyle is exposed as a static member on ImmersionStyle, so the canonical way to name it is the leading-dot form rather than the full type name. In the example the selection is initialized with
.automatic, which resolves to this style and tells the system to pick an appropriate immersion level for you.Hold the selection in state typed as any ImmersionStyle
Because several immersion styles share the ImmersionStyle protocol, you store the current choice as an existential so it can change at runtime. Here
@State private var style: any ImmersionStyle = .automatickeeps.automaticas the active value while leaving room to assign a different conforming style later.Pass it to immersionStyle(selection:in:)
You apply an immersion style by binding your state to the immersionStyle(selection:in:) modifier on an ImmersiveSpace; the modifier reads the bound value and drives how much passthrough the space shows. The
styleproperty in the example is exactly the kind of binding source that modifier consumes, with.automaticas its initial entry.Reassign the value to change the style at runtime
Since the selection is mutable state, writing a new ImmersionStyle into it updates the space live. The
.onAppear { style = .automatic }block shows the assignment pattern; substituting another conforming style on that line is all it takes to hand control away from AutomaticImmersionStyle.
.onAppear { style = .automatic } assignment to style = .full and watch the selection move from system-chosen immersion to a fully immersive space.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 AutomaticImmersionStyleDemo: View {
@State private var style: any ImmersionStyle = .automatic
var body: some View {
VStack(spacing: 12) {
Image(systemName: "visionpro")
.font(.largeTitle)
Text("Immersive Space")
.font(.headline)
Text("Style: .automatic")
.font(.subheadline)
.foregroundStyle(.secondary)
}
.padding()
.onAppear { style = .automatic }
}
}