TechnologiesSwiftUIScenes and Windows

SceneLaunchBehavior struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The launch behavior for a scene.

How it works

SceneLaunchBehavior is a structure of constants that tell SwiftUI how a scene should behave when your app launches. By default a scene type may or may not present a window at startup; this type lets you state your intent explicitly, choosing whether a given scene appears automatically or stays out of the way until something asks for it. Reach for SceneLaunchBehavior when a window, settings panel, or auxiliary scene shouldn't open on its own at launch, and apply it through a scene's launchBehavior(_:) modifier so the system honors your decision when restoring or creating the app's initial scenes.

  1. Choose a launch behavior with .presented or .suppressed

    SceneLaunchBehavior exposes its options as type properties you select with leading-dot syntax, so a value reads like a clear statement of intent. The example holds one in behavior: SceneLaunchBehavior = .presented, declaring that this scene should be shown at launch; the complementary .suppressed case keeps the scene from appearing until it's explicitly requested.

  2. Apply it to a scene with launchBehavior(_:)

    You don't construct windows from a SceneLaunchBehavior directly; you hand the value to a scene's launchBehavior(_:) modifier, which is where the constant takes effect. The caption text spells out the intended call site, Window().launchBehavior(.presented), showing the behavior being attached to a scene so SwiftUI applies it when assembling the app's scenes.

  3. Compare behaviors as plain values

    Because SceneLaunchBehavior is a value type whose constants are equatable, you can test which behavior you're holding the same way you'd compare any simple value. The example branches on behavior == .presented to drive its UI, confirming that a SceneLaunchBehavior reads cleanly in conditionals and can flow through ordinary Swift logic before it ever reaches a scene.

  4. Surface the current behavior in the interface

    Since the chosen behavior is just data, you can store it in a property and reflect it back to the user. Here the equality check feeds a ternary that renders "Presented" or "Suppressed" into a Text, making the selected SceneLaunchBehavior visible and demonstrating that the value is fully inspectable at the call site, not just an opaque flag passed to the system.

Try it — Change the stored value from let behavior: SceneLaunchBehavior = .presented to .suppressed and watch the label flip from "Presented" to "Suppressed", mirroring the scene that would no longer open automatically at launch.

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.

SceneLaunchBehavior.swift
struct SceneLaunchBehaviorDemo: View {
    let behavior: SceneLaunchBehavior = .presented
    var body: some View {
        VStack(spacing: 12) {
            Image(systemName: "macwindow.badge.plus")
                .font(.largeTitle)
                .foregroundStyle(.tint)
            Text("Scene Launch Behavior")
                .font(.headline)
            Text(behavior == .presented ? "Presented" : "Suppressed")
                .font(.subheadline)
                .foregroundStyle(.secondary)
            Text("Used as Window().launchBehavior(.presented)")
                .font(.caption)
                .multilineTextAlignment(.center)
                .foregroundStyle(.tertiary)
        }
        .padding()
    }
}
Live preview
Scene Launch Behavior Presented Used as Window().launchBehavior(.presented)
Scene Launch Behavior Presented Used as Window().launchBehavior(.presented)
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →