<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macOS: 14.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/DocumentGroup/init(editing:contentType:editor:prepareDocument:)-7uvjw",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI13DocumentGroupV01_a5Data_aB0AD05ModelC0VRszrlE7editing11contentType6editor07prepareC0ACyAFq_G0aE0010PersistentF0_pXp_07UniformI11Identifiers6UTTypeVq_ycyAL0F7ContextCctcfc"
  },
  "title" : "init(editing:contentType:editor:prepareDocument:)"
}
-->

# init(editing:contentType:editor:prepareDocument:)

Instantiates a document group for creating and editing
documents that store a specific model type.

```
nonisolated init(editing modelType: any PersistentModel.Type, contentType: UTType, editor: @escaping () -> Content, prepareDocument: @escaping (ModelContext) -> Void = { _ in })
```

## Parameters

`modelType`

The model type defining the schema used for each document.

`contentType`

The content type of the document.
It should conform to `UTType.package`.

`editor`

The editing UI for the provided document.

`prepareDocument`

The optional closure that accepts
`ModelContext` associated with the new document.
Use this closure to set the document’s initial contents
before it is displayed: insert preconfigured models
in the provided `ModelContext`.

## Discussion

```
 @main
 struct Todo: App {
     var body: some Scene {
         DocumentGroup(editing: TodoItem.self, contentType: .todoItem) {
             ContentView()
         }
     }
 }

 struct ContentView: View {
     @Query var items: [TodoItem]

         var body: some View {
             List {
                 ForEach(items) { item in
                     @Bindable var item = item
                     Toggle(item.text, isOn: $item.isDone)
                 }
              }
         }
 }

 @Model
 final class TodoItem {
     var created: Date
     var text: String
     var isDone = false
 }

 extension UTType {
     static var todoItem = UTType(exportedAs: "com.myApp.todoItem")
 }
```

> Important: If your app declares custom uniform type identifiers,
> include corresponding entries in the app’s `Info.plist`.
> For more information, see <doc://com.apple.documentation/documentation/uniformtypeidentifiers/defining_file_and_data_types_for_your_app>.
> Also, remember to specify the supported Document types in the Info.plist as well.

---

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)