---
title: NewDocumentAction
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/newdocumentaction
---

# NewDocumentAction

An action that presents a new document.

## Declaration

```swift
@MainActor @preconcurrency struct NewDocumentAction
```

## Overview

Overview Use the newDocument environment value to get the instance of this structure for a given Environment. Then call the instance to present a new document. You call the instance directly because it defines a callAsFunction(_:) method that Swift calls when you call the instance. For example, you can define a button that creates a new document from the selected text: struct NewDocumentFromSelection: View {     @FocusedBinding(\.selectedText) private var selectedText: String?     @Environment(\.newDocument) private var newDocument

var body: some View {         Button("New Document With Selection") {             newDocument(TextDocument(text: selectedText))         }         .disabled(selectedText?.isEmpty != false)     } } The above example assumes that you define a TextDocument that conforms to the FileDocument or ReferenceFileDocument protocol, and a DocumentGroup that handles the associated file type.

## Topics

### Calling the action

- [callAsFunction(_:)](swiftui/newdocumentaction/callasfunction(_:).md)
- [callAsFunction(contentType:)](swiftui/newdocumentaction/callasfunction(contenttype:).md)
- [callAsFunction(contentType:prepareDocument:)](swiftui/newdocumentaction/callasfunction(contenttype:preparedocument:).md)

## Relationships

### Conforms To

- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Opening a document programmatically

- [newDocument](swiftui/environmentvalues/newdocument.md)
- [openDocument](swiftui/environmentvalues/opendocument.md)
- [OpenDocumentAction](swiftui/opendocumentaction.md)
