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.
Choose a restoration policy with the type's constants
SceneRestorationBehavior exposes named cases that stand in for each restoration mode.
.automaticlets SwiftUI apply the system's default behavior for the scene's type, while.disabledopts 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.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.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
VStackofLabelrows is only signage describing the choices; in a real app the same.restorationBehavior(_:)call sits on the scene declaration that owns the window.Distinguish restored scenes from fresh ones
Picking
.disabledguarantees 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.automatickeeps the platform's normal continuity, letting the scene's navigation and contents return as the user expects on the next launch.
.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.
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()
}
}