One Logo Pool Ball
SwiftUI · IOS API REFERENCE

NewDocumentButton

struct · iOS 18.0+ · SDK 27.1

nonisolated struct NewDocumentButton<Label> where Label : View

A button that creates and opens new documents. Use a new document button to give people the option to create documents in your app. In the following example, there are two new document buttons, both support ``Text`` labels. When the user taps or clicks the first button, the system creates a new document in the directory currently open in the document browser. The second button presents a template picker, where a document can be prepopulated or preconfigured using a template. @State private var isTemplatePickerPresented = false @State private var documentCreationContinuation: CheckedContinuation<TextDocument?, any Error>? var body: some Scene { DocumentGroupLaunchScene("My Documents") { NewDocumentButton(Text("Start Writing…")) NewDocumentButton(Text("Choose a Template"), for: TextDocument.self) { try await withCheckedThrowingContinuation { continuation in documentCreationContinuation = continuation isTemplatePickerPresented = true } } .fullScreenCover(isPresented: $isTemplatePickerPresented) { TemplatePicker( continuation: $documentCreationContinuation ) } } DocumentGroup(newDocument: TextDocument()) { configuration in MyDocumentView(document: configuration.$document)) } } struct TemplatePicker: View { @Binding var continuation: CheckedContinuation<TextDocument?, any Error>? @Environment(\.dismiss) var dismiss var body: some View { VStack { Text("Choose a template") .font(.title) Button("Meeting minutes") { let document = makeMeetingMinutes() documentCreationContinuation?.resume(returning: document) dismiss() } Button("Letter") { let document = makeLetter() documentCreationContinuation?.resume(returning: document) dismiss() } Button("Cancel") { documentCreationContinuation?.resume(throwing: CancellationError()) dismiss() } } } private func makeMeetingMinutes() -> TextDocument { ... } private func makeLetter() -> TextDocument { ... } } struct TextDocument: FileDocument { ... } If you don't provide a custom label, the system provides a button with the default "Create Document" label.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

9 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

NewDocumentButton.body

This protocol needs associated types that cannot yet cross the bridge.

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

NewDocumentButton.init(_:for:contentType:prepareDocument:)

The containing type needs Swift generic type arguments. (no canonical witness for D)

All SwiftUI types →