<!--
{
  "availability" : [
    "iOS: 14.0.0 - 27.0.0",
    "iPadOS: 14.0.0 - 27.0.0",
    "macCatalyst: 14.0.0 - 27.0.0",
    "macOS: 11.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/DocumentGroup/init(newDocument:editor:)-4toe2",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI13DocumentGroupVA2A04FileC0RzrlE03newC06editorACyxq_GxyXA_q_AA0eC13ConfigurationVyxGctcfc"
  },
  "title" : "init(newDocument:editor:)"
}
-->

# init(newDocument:editor:)

Creates a document group for creating and editing file documents.

```
@preconcurrency nonisolated init(newDocument: @autoclosure @escaping @Sendable () -> Document, @ContentBuilder editor: @escaping (FileDocumentConfiguration<Document>) -> Content)
```

## 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. On 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.

With the `newDocument:` initializer, SwiftUI considers your app as an
editor of documents of given content types
(`FileDocument.writableContentTypes`). On macOS, this adds
a File > New menu item and enables the standard document commands.

On iOS, it shows a New Document button in the document browser.
The `FileDocumentConfiguration/isEditable`
property is `true`. Use the `DocumentGroup/init(viewing:editor:)`
initializer instead if your app should only display documents without
modifying them.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)