TechnologiesSwiftUI

WindowManagerRole struct

iOSmacOStvOSwatchOSvisionOSiOS 18.0+✓ renders

Options for defining how a scene's windows behave when used within a managed

How it works

WindowManagerRole describes how the windows a scene produces participate in full screen and Stage Manager on macOS. Each scene has one of three roles: a principal window anchors a full-screen or Stage Manager grouping, an associated window may join a principal window's grouping but never forms one on its own, and the automatic role lets SwiftUI infer the right behavior from the scene's type and position. Reach for it through the windowManagerRole(_:) scene modifier when the default inference doesn't match how you want a secondary window to behave, such as promoting an auxiliary Window to be a full-screen anchor.

  1. Choose a role with the static members

    WindowManagerRole is a value type whose meaningful values come from three static properties rather than an initializer: .automatic, .principal, and .associated. The example binds one directly with let role: WindowManagerRole = .principal, which is the role that lets a scene's windows appear in full screen or Stage Manager as the anchor of their grouping.

  2. Let .automatic defer to the scene

    WindowManagerRole.automatic is the default and asks SwiftUI to pick a role from the scene's type and configuration. On macOS a WindowGroup or DocumentGroup resolves to principal, while a Window is principal only when it is the first scene declared and associated otherwise; Settings resolves to associated.

  3. Distinguish .principal from .associated

    .principal makes the scene's windows able to enter full screen or Stage Manager and lead that grouping, whereas .associated windows can ride alongside a principal window in those modes but cannot trigger them by themselves. Picking between these two is the whole point of the type: in the example, choosing .principal over .associated is what changes whether role represents an anchor or a companion window.

  4. Apply it with windowManagerRole(_:)

    You attach a WindowManagerRole to a scene, not a view, using the Scene/windowManagerRole(_:) modifier to override the inferred behavior. A secondary Window("Organizer", id: "organizer") declared after a WindowGroup would normally be associated, but .windowManagerRole(.principal) promotes it so its windows can anchor full screen and Stage Manager.

  5. Inspect the chosen value

    Because the type conforms to nothing beyond Sendable, the example surfaces the selected role for display by funneling it through String(describing: role) inside a Text, turning the stored .principal value into readable text. This is illustrative only -- the role's effect is on scene window management, which surfaces in a real app's scene definition rather than in a view's body.

Try it — Change let role: WindowManagerRole = .principal to .associated (or .automatic) and watch the displayed String(describing: role) text update to the role that would govern the scene's full-screen and Stage Manager participation.

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.

WindowManagerRole.swift
struct WindowManagerRoleDemo: View {
    let role: WindowManagerRole = .principal
    var body: some View {
        VStack(spacing: 8) {
            Image(systemName: "macwindow")
                .font(.largeTitle)
            Text("Window Manager Role")
                .font(.headline)
            Text("\(String(describing: role))")
                .font(.subheadline)
                .foregroundStyle(.secondary)
        }
        .padding()
    }
}
Live preview
Window Manager Role {String(describing: role)}
Window Manager Role {String(describing: role)}
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →