init(_:contentType:source:_:)
Creates and opens new URL-based documents from a template picker.
Declaration
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 or Urldocumentconfiguration.
- prepareDocumentURL:
Called when the user taps the button. Present a template picker or other UI, then return the URL of the prepared document,
nilto request an empty document, or throw on cancellation.
Discussion
NewDocumentButton(
contentType: .text,
source: .template
) {
try await withCheckedThrowingContinuation { continuation in
documentCreationContinuation = continuation
showTemplatePicker = true
}
}