<!--
{
  "availability" : [
    "macOS: 14.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/NewDocumentAction/callAsFunction(contentType:prepareDocument:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17NewDocumentActionV01_a5Data_aB0E14callAsFunction11contentType07prepareD0y07UniformK11Identifiers6UTTypeV_y0aF012ModelContextCctF"
  },
  "title" : "callAsFunction(contentType:prepareDocument:)"
}
-->

# callAsFunction(contentType:prepareDocument:)

Presents a new document window with preset contents.

```
@MainActor @preconcurrency func callAsFunction(contentType: UTType, prepareDocument: @escaping (ModelContext) -> Void)
```

## Parameters

`contentType`

The content type of the document.

`prepareDocument`

The 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

Don’t call this method directly. SwiftUI calls it when you
call the [`newDocument`](/documentation/SwiftUI/EnvironmentValues/newDocument) action.

For example, a Todo app might have a way to create
a sample prepopulated Todo list as a part
of onboarding experience:

```
newDocument(contentType: .todoList) { modelContext in
    let todoList = TodoList(
        title: "🎬 Movie night",
        items: [
            TodoItem(title: "🍿 Buy popcorn"),
            TodoItem(title: "🍨 Make some ice cream",
            TodoItem(title: "💡 Hang a string of lights")
        ]
    )
    modelContext.insert(todoList)
}
```

For information about how Swift uses the `callAsFunction()` method to
simplify call site syntax, see
[Methods with Special Names](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID622)
in *The Swift Programming Language*.

---

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)