<!--
{
  "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:documents:contentType:onCompletion:)-6xyj7",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12fileExporter11isPresented9documents11contentType12onCompletionQrAA7BindingVySbG_qd__07UniformJ11Identifiers6UTTypeVys6ResultOySay10Foundation3URLVGs5Error_pGctSlRd__AA12FileDocument7ElementRpd__lF"
  },
  "title" : "fileExporter(isPresented:documents:contentType:onCompletion:)"
}
-->

# fileExporter(isPresented:documents:contentType:onCompletion:)

Presents a system dialog for exporting a collection of value type
documents to files on disk.

```
nonisolated func fileExporter<C>(isPresented: Binding<Bool>, documents: C, contentType: UTType, onCompletion: @escaping (Result<[URL], any Error>) -> Void) -> some View where C : Collection, C.Element : FileDocument
```

## Parameters

`isPresented`

A binding to whether the dialog should be shown.

`documents`

The collection of in-memory documents to export.

`contentType`

The content type to use for the exported file.

`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 `documents` must not be empty. 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 collection of text documents might
look like this:

```
struct ExportAllButton: View {
    @State private var isExporterPresented = false
    var documents: [TextFile]

    var body: some View {
        Button("Export All") {
            isExporterPresented = true
        }
        .fileExporter(
            isPresented: $isExporterPresented,
            documents: documents,
            contentType: .utf8PlainText
        ) { result in
            switch result {
            case .success(let urls):
                urls.forEach { print("Saved to \($0)") }
            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)