Initializer

init(newDocument:editor:)

Creates a document group for creating and editing file documents.

Declaration 宣言

init(newDocument: @autoclosure @escaping () -> Document, editor: @escaping (FileDocumentConfiguration<Document>) -> Content)
Available when Document conforms to FileDocument and Content conforms to View. DocumentFileDocumentに準拠する、そしてContentViewに準拠する場合に利用可能です。

Parameters パラメータ

newDocument

The initial document to use when a user creates a new document.

editor

The editing UI for the provided document.

Discussion 議論

Use a DocumentGroup scene to tell SwiftUI what kinds of documents your app can open when you declare your app using the App protocol. You initialize a document group scene by passing in the document model and a view capable of displaying the document’s contents. The document types you supply to DocumentGroup must conform to FileDocument or ReferenceFileDocument. SwiftUI uses the model to add document support to your app. In macOS this includes document-based menu support including the ability to open multiple documents. In iOS this includes a document browser that can navigate to the documents stored on the file system and multiwindow support:


@main
struct MyApp: App {
    var body: some Scene {
        DocumentGroup(newDocument: TextFile()) { file in
            ContentView(document: file.$document)
        }
    }
}

The document types you supply to DocumentGroup must conform to FileDocument or ReferenceFileDocument. Your app can support multiple document types by adding additional DocumentGroup scenes.

See Also 参照

Creating a Document Group 書類グループを作成する