<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/NewDocumentButton",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17NewDocumentButtonV"
  },
  "title" : "NewDocumentButton"
}
-->

# NewDocumentButton

A button that creates and opens new documents.

```
nonisolated struct NewDocumentButton<Label> where Label : View
```

## Overview

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`](/documentation/SwiftUI/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.

## Topics

### Creating and opening a document

[`init ( _ : contentType :)`](/documentation/SwiftUI/NewDocumentButton/init(_:contentType:))

Creates and opens new documents.

[`init ( _ : contentType : prepareDocumentURL :)`](/documentation/SwiftUI/NewDocumentButton/init(_:contentType:prepareDocumentURL:))

Creates and opens new documents.

### Creating and opening a document with a creation source

[`init ( _ : contentType : source :)`](/documentation/SwiftUI/NewDocumentButton/init(_:contentType:source:))

Creates and opens new documents, tagging them with a creation source.

[`init(_:contentType:source:_:)`](/documentation/SwiftUI/NewDocumentButton/init(_:contentType:source:_:))

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

[`init ( _ : contentType : source : prepareDocumentURL :)`](/documentation/SwiftUI/NewDocumentButton/init(_:contentType:source:prepareDocumentURL:))

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

### Deprecated

[`init ( _ : for : contentType : prepareDocument :)`](/documentation/SwiftUI/NewDocumentButton/init(_:for:contentType:prepareDocument:))

## Relationships

### Conforms To

[`View`](/documentation/SwiftUI/View)

---

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)