6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【SwiftUI】WindowGroupを読む

Last updated at Posted at 2020-11-11

この投稿は何か?

SwiftUIフレームワークにおけるWindowGroupについて、Apple Developerサイトのリファレンスを独自に翻訳・解釈したものです。

WindowGroup構造体

形式的に構造化されたウィンドウをまとめたシーンです。

WindowGroup構造体の宣言
struct WindowGroup<Content> where Content : View

アプリで表示されるビュー階層のコンテナとしてWindowGroupを使用します。グループのコンテンツとして宣言した階層は、アプリがそのグループから作成する各ウィンドウのテンプレートとして機能します。

アプリケーションに定義されたWindowGroup
@main
struct Mail: App {
    var body: some Scene {
        WindowGroup {
            MailViewer() // Declare a view hierarchy here.
        }
    }
}

SwiftUIはプラットフォーム固有の動作を扱います。例えば、SwiftUIをサポートしているmacOSやiPadOSでは、ユーザーはグループから複数のウィンドウを同時に開くことができます。macOSでは、ユーザーは開いているウィンドウをタブ付きインターフェイスにまとめることができます。また、ウィンドウグループは「標準的にウィンドウを管理するコマンド」を自動的に提供します。

グループから作成されたすべてのウィンドウは、状態が互いに影響しません。例えば、グループから新たに作成されたウィンドウごとに、システムはシーンのビュー階層によってインスタンス化されたStateまたはStateObject変数のための新しいストレージを割り当てます。

ドキュメントベースではないアプリケーションの場合、主なインターフェイスにはウィンドウグループを使用します。ドキュメントベースのアプリでは、DocumentGroupを使用します。

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?