TechnologiesSwiftUI

Scene protocol

iOSmacOStvOSwatchOSvisionOSiOS 14.0+✓ renders

A part of an app's user interface with a life cycle managed by the

How it works

A scene represents a part of your app's user interface that the system manages and presents on screen, such as a window, a window group, or a document. You compose scenes inside the body of an App to declare the top-level containers your app shows, and the system handles their lifecycle — creating, showing, and removing them as the platform and the person using your app require. Reach for Scene when you need to describe what your app presents at the window level, above the view hierarchy: it is the bridge between your App declaration and the view content it ultimately displays. Like View, you rarely conform to Scene directly; instead you build scenes by combining the concrete types SwiftUI provides.

  1. Return scenes from an App's body

    An App's body is a Scene, so the scenes you compose there become your app's presentable surfaces. The illustrative SceneDemo here is a View standing in for the content a scene would host — in a real app that content goes inside a scene returned from the app body, with the scene defining the window that frames it.

  2. Use WindowGroup as the primary scene type

    WindowGroup is the most common concrete Scene: it manages a group of identically structured windows, presenting one on launch and creating more as the platform allows. The Text("WindowGroup") label in the example points at exactly this type — the scene that would wrap content like the VStack shown and present it as a window.

  3. Choose other scene types for different presentations

    Beyond WindowGroup, SwiftUI offers scenes such as DocumentGroup for document-based apps, Settings for a macOS preferences window, and WindowGroup variants for auxiliary windows. Each conforms to Scene, so they compose in the same place; you pick the scene that matches how the system should present the UI built from views like the Image and Text in this example.

  4. Apply scene modifiers to configure presentation

    Scene exposes modifiers that adjust window-level behavior rather than view-level layout — for example commands(_:) to add menu bar commands, windowStyle(_:) and windowResizability(_:) to shape the window, and defaultSize(_:) to suggest an initial size. These attach to the scene that hosts content like the padded VStack, leaving the view's own modifiers such as .font and .foregroundStyle untouched.

  5. Combine scenes for richer apps

    Because every scene conforms to Scene, you can list several together in an app body to present multiple windows or surfaces at once — a main WindowGroup alongside a Settings scene, for instance. SwiftUI treats the group as the app's scene, managing each member independently while it shows content built from views like SceneDemo.

Try it — Wrap the SceneDemo content in a WindowGroup returned from an App body and run it, then add a second scene alongside it to watch the app present an additional managed window.

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.

Scene.swift
struct SceneDemo: View {
    var body: some View {
        VStack(spacing: 12) {
            Image(systemName: "macwindow")
                .font(.largeTitle)
                .foregroundStyle(.tint)
            Text("WindowGroup")
                .font(.headline)
            Text("A Scene defines a window or UI shown by an App.")
                .font(.caption)
                .foregroundStyle(.secondary)
                .multilineTextAlignment(.center)
        }
        .padding()
    }
}
Live preview
WindowGroup A Scene defines a window or UI shown by an App.
WindowGroup A Scene defines a window or UI shown by an App.
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →