> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swiftui/app/scenes/scene.md).

# Scene

[SwiftUI](/ios/swiftui.md) ⟩ [scenes](/ios/swiftui/app/scenes.md) ⟩ Scene (protocol)

{% hint style="success" %}
A [protocol](/ios/swift/type/category/protocol.md) that a [scene](/ios/swiftui/app/scenes.md) must conform to.
{% endhint %}

* 管理應用程式的「起始畫面」與「顯示範圍」。

{% tabs %}
{% tab title="🔴 主題" %}

* [WindowGroup](/ios/swiftui/app/windows/windowgroup.md)：自訂介面（可以有多個視窗）
* DocumentGroup：自動處理文件開啟、儲存、關閉等功能
* SettingsScene：建立應用程式的設定介面（主要用於 macOS）
  {% endtab %}

{% tab title="💾 程式" %}

```swift
import SwiftUI

@main
struct MyApp: App {
    // ⭐️  `App` protocol requirement
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
```

📁 custom scene

```swift
struct MyScene: Scene {
    // ⭐️  `Scene` protocol requirement
    var body: some Scene {
        WindowGroup {
            MyRootView()
        }
    }
}
```

{% endtab %}

{% tab title="📘 手冊" %}

* [SwiftUI](https://developer.apple.com/documentation/swiftui) ⟩ [Scenes](https://developer.apple.com/documentation/swiftui/scenes) ⟩ [Scene](https://developer.apple.com/documentation/swiftui/scene) ⟩
  * [DocumentGroup](https://developer.apple.com/documentation/swiftui/documentgroup)&#x20;
  * &#x20;[WindowGroup](https://developer.apple.com/documentation/swiftui/windowgroup)
    {% endtab %}

{% tab title="📗 參考" %}

* [ ] heckj ⟩ [SwiftUI Field Notes: DocumentGroup](https://rhonabwy.com/2022/07/19/swiftui-field-notes-documentgroup/)
  {% endtab %}
  {% endtabs %}
