<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/fileExporter(isPresented:documents:contentTypes:onCompletion:onCancellation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12fileExporter11isPresented9documents12contentTypes12onCompletion0K12CancellationQrAA7BindingVySbG_qd__Say22UniformTypeIdentifiers6UTTypeVGys6ResultOySay10Foundation3URLVGs5Error_pGcyycSgtSlRd__AA16WritableDocument7ElementRpd__AUA__6Writer11DestinationRTd__lF::OverloadGroup"
  },
  "title" : "fileExporter(isPresented:documents:contentTypes:onCompletion:onCancellation:)"
}
-->

# fileExporter(isPresented:documents:contentTypes:onCompletion:onCancellation:)

Presents a system dialog for allowing the user to export a
collection of objects conforming to `WritableDocument` to files
on disk.

```
nonisolated func fileExporter<C>(isPresented: Binding<Bool>, documents: C, contentTypes: [UTType] = [], onCompletion: @escaping (Result<[URL], any Error>) -> Void, onCancellation: (() -> Void)? = nil) -> some View where C : Collection, C.Element : WritableDocument, C.Element.Writer.Destination == URL
```

## Parameters

`isPresented`

A binding to whether the dialog should be shown.

`documents`

The in-memory documents to export.

`contentTypes`

The content types to export to. If not provided,
`WritableDocument.writableContentTypes` are used.

`onCompletion`

A callback that will be invoked when the operation
has succeeded or failed. The `result` indicates whether
the operation succeeded or failed.

`onCancellation`

A callback that will be invoked
if the user cancels the operation.

## Discussion

In order for the dialog to appear, `documents` must be non-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 `onCancellation` will be
called.

```
@MainActor
final class TextDocument: WritableDocument {
    static let writableContentTypes: [UTType] = [.utf8PlainText]

    var text: String = ""

    nonisolated func writer(
        configuration: sending WriteConfiguration
    ) -> sending FileWrapperDocumentWriter<String> {
        FileWrapperDocumentWriter(configuration) { snapshot, _ in
            FileWrapper(regularFileWithContents: Data(snapshot.utf8))
        }
    }

    func snapshot(contentType: UTType) async throws -> String {
        text
    }
}

struct ExportView: View {
    @Binding var documents: [TextDocument]
    @State private var isExporting = false

    var body: some View {
        Button("Export…") { isExporting = true }
            .fileExporter(
                isPresented: $isExporting,
                documents: documents
            ) { _ in }
    }
}
```

---

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)