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.
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.suppressedcase keeps the scene from appearing until it's explicitly requested.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.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 == .presentedto drive its UI, confirming that a SceneLaunchBehavior reads cleanly in conditionals and can flow through ordinary Swift logic before it ever reaches a scene.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 aText, 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.
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.
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()
}
}