TechnologiesSwiftUIScenes and Windows

SceneRestorationBehavior struct

iOSmacOStvOSwatchOSvisionOSiOS 18.0+✓ renders

The restoration behavior for a scene.

How it works

SceneRestorationBehavior is a set of constants that tell SwiftUI whether the system should reconstruct a scene's user-interface state when that scene is relaunched. When a person quits and reopens your app, or the system reclaims and later restores a window, the framework can either bring back the prior contents and navigation of a scene or start it fresh. Use SceneRestorationBehavior to make that policy explicit per scene, so that windows you expect to resume exactly where the user left off do so, while transient or sensitive windows always begin in a clean state.

  1. Choose a restoration policy with the type's constants

    SceneRestorationBehavior exposes named cases that stand in for each restoration mode. .automatic lets SwiftUI apply the system's default behavior for the scene's type, while .disabled opts the scene out so it always relaunches without restored state. You select one of these constants and hand it to the scene to declare your intent.

  2. Apply it with restorationBehavior(_:)

    The value reaches a scene through the restorationBehavior(_:) scene modifier, which takes a SceneRestorationBehavior and attaches it to the scene it modifies. The example notes this directly: the policy is "Applied via .restorationBehavior(_:) on a Window scene." The modifier is the connection point between the constant you pick and the scene whose lifecycle it governs.

  3. Attach it to a window-bearing scene

    SceneRestorationBehavior is meaningful where there is window state to preserve, so you apply it to scenes such as Window or WindowGroup rather than to an individual view. The demo's VStack of Label rows is only signage describing the choices; in a real app the same .restorationBehavior(_:) call sits on the scene declaration that owns the window.

  4. Distinguish restored scenes from fresh ones

    Picking .disabled guarantees a scene starts from its initial configuration every time, which suits login windows, one-off panels, or content you never want resurrected. Leaving it at .automatic keeps the platform's normal continuity, letting the scene's navigation and contents return as the user expects on the next launch.

Try it — Change the scene's .restorationBehavior(_:) argument from .automatic to .disabled, relaunch the app, and observe that the window comes back empty instead of resuming its previous state.

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.

SceneRestorationBehavior.swift
struct SceneRestorationBehaviorDemo: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Text("Scene Restoration")
                .font(.headline)
            Label(".automatic", systemImage: "arrow.clockwise")
                .foregroundStyle(.blue)
            Label(".disabled", systemImage: "xmark.circle")
                .foregroundStyle(.secondary)
            Text("Applied via .restorationBehavior(_:) on a Window scene.")
                .font(.caption)
                .foregroundStyle(.secondary)
        }
        .padding()
    }
}
Live preview
Scene Restoration .automatic .disabled Applied via .restorationBehavior(_:) on a Window scene.
Scene Restoration .automatic .disabled Applied via .restorationBehavior(_:) on a Window scene.
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →