---
title: "init(_:contentType:source:_:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/newdocumentbutton/init(_:contenttype:source:_:)"
---

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

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

## Declaration

```swift
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 doc://com.apple.SwiftUI/documentation/SwiftUI/FileDocumentConfiguration or doc://com.apple.SwiftUI/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

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