<!--
{
  "availability" : [
    "iOS: 14.0.0 - 27.0.0",
    "iPadOS: 14.0.0 - 27.0.0",
    "macCatalyst: 14.0.0 - 27.0.0",
    "macOS: 11.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:)-32vwk",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12fileExporter11isPresented8document11contentType15defaultFilename12onCompletionQrAA7BindingVySbG_qd__Sg07UniformJ11Identifiers6UTTypeVSSSgys6ResultOy10Foundation3URLVs5Error_pGctAA12FileDocumentRd__lF"
  },
  "title" : "fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:)"
}
-->

# fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:)

Presents a system dialog for exporting a document that’s stored in
a value type, like a structure, to a file on disk.

```
nonisolated func fileExporter<D>(isPresented: Binding<Bool>, document: D?, contentType: UTType, defaultFilename: String? = nil, onCompletion: @escaping (Result<URL, any Error>) -> Void) -> some View where D : FileDocument
```

## Parameters

`isPresented`

A binding to whether the dialog should be shown.

`document`

The in-memory document to export.

`contentType`

The content type to use for the exported file.

`defaultFilename`

If provided, the default name to use for the
exported file, which the user will have an opportunity to edit
prior to the export.

`onCompletion`

A callback that will be invoked when the operation has
succeeded or failed.

- result: A `Result` indicating whether the operation succeeded or
  failed.

## Discussion

In order for the dialog to appear, both `isPresented` must be `true`
and `document` must not be `nil`. When the operation is finished,
`isPresented` will be set to `false` before `onCompletion` is called. If
the user cancels the operation, `isPresented` will be set to `false` and
`onCompletion` will not be called.

The `contentType` provided must be included within the document type’s
`writableContentTypes`, otherwise the first valid writable content type
will be used instead.

For example, a button that exports a text document might look like this:

```
struct ExportButton: View {
    @State private var isExporterPresented = false
    var document: TextFile?

    var body: some View {
        Button("Export") {
            isExporterPresented = true
        }
        .fileExporter(
            isPresented: $isExporterPresented,
            document: document,
            contentType: .utf8PlainText,
            defaultFilename: "Exported Document"
        ) { result in
            switch result {
            case .success(let url):
                print("Saved to \(url)")
            case .failure(let error):
                print(error)
            }
        }
    }
}
```

To further configure the dialog’s appearance and behavior, use these
view modifiers: `fileDialogDefaultDirectory(_:)`,
`fileDialogConfirmationLabel(_:)`, `fileDialogMessage(_:)`,
`fileDialogBrowserOptions(_:)`,
`fileExporterFilenameLabel(_:)`, and
`fileDialogCustomizationID(_:)`.

---

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)