<!--
{
  "availability" : [
    "macOS: 13.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/EnvironmentValues/newDocument",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17EnvironmentValuesVAAE11newDocumentAA03NewF6ActionVvp"
  },
  "title" : "newDocument"
}
-->

# newDocument

An action in the environment that presents a new document.

```
var newDocument: NewDocumentAction { get }
```

## Discussion

Use the `newDocument` environment value to get the instance of the
[`NewDocumentAction`](/documentation/SwiftUI/NewDocumentAction) structure for a given [`Environment`](/documentation/SwiftUI/Environment). Then call
the instance to present a new document. You call the instance directly
because it defines a [`callAsFunction(_:)`](/documentation/SwiftUI/NewDocumentAction/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`](/documentation/SwiftUI/FileDocument) or [`ReferenceFileDocument`](/documentation/SwiftUI/ReferenceFileDocument)
protocol, and a [`DocumentGroup`](/documentation/SwiftUI/DocumentGroup) that handles the associated file type.

---

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)