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

# init(_:contentType:source:_:)

Creates and opens new URL-based documents from a template picker.

```
nonisolated init(_ label: Text? = nil, contentType: UTType, source: DocumentCreationSource, _ prepareDocumentURL: @escaping () async throws -> URL? = { nil })
```

## Parameters

`label`

A label for the button.

`contentType`

The content type of the document to create.

`source`

A source for the document creation flow. When a document is
created, you can retrieve its source from [`FileDocumentConfiguration`](/documentation/SwiftUI/FileDocumentConfiguration)
or [`URLDocumentConfiguration`](/documentation/SwiftUI/URLDocumentConfiguration).

`prepareDocumentURL`

Called when the user taps the button. Present
a template picker or other UI, then return the URL of the prepared
document, `nil` to request an empty document, or throw on
cancellation.

## Discussion

```
NewDocumentButton(
    contentType: .text,
    source: .template
) {
    try await withCheckedThrowingContinuation { continuation in
        documentCreationContinuation = continuation
        showTemplatePicker = true
    }
}
```

---

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)