<!--
{
  "availability" : [
    "iOS: 18.0.0 - 27.0.0",
    "iPadOS: 18.0.0 - 27.0.0",
    "macCatalyst: 18.0.0 - 27.0.0",
    "macOS: 15.0.0 - 27.0.0",
    "visionOS: 2.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/NewDocumentButton/init(_:for:contentType:prepareDocument:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17NewDocumentButtonVA2A4TextVRszrlE_3for11contentType07prepareD0ACyAEG10Foundation23LocalizedStringResourceV_qd__m07UniformI11Identifiers6UTTypeVSgqd__SgyYaKctcAA04FileD0Rd__lufc::OverloadGroup"
  },
  "title" : "init(_:for:contentType:prepareDocument:)"
}
-->

# init(_:for:contentType:prepareDocument:)

```
@export(implementation) nonisolated init<D>(_ title: LocalizedStringResource, for documentType: D.Type = D.self, contentType: UTType? = nil, prepareDocument: @escaping () async throws -> D? = { nil }) where D : FileDocument
```

## Parameters

`title`

A title resource for the button.

`documentType`

A type of the document to create.

`contentType`

An optional content type of the document to create.

`prepareDocument`

A closure is called when a user presses the button.
At this point, you can present a document template picker or another
UI that allows users to choose a theme, configuration, or a template
to create a document from.
Return a prepared document, or throw an error if document creation
failed.
Return `nil` to request creation of an empty document.

---

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)