---
title: "fileExporter(isPresented:documents:contentType:onCompletion:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/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.

## Declaration

```swift
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.

## Discussion

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(_:).

## See Also

### Exporting to file

- [fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:)](swiftui/view/fileexporter(ispresented:document:contenttype:defaultfilename:oncompletion:).md)
- [fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:document:contenttype:defaultfilename:oncompletion:oncancellation:).md)
- [fileExporter(isPresented:document:contentTypes:defaultFilename:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:document:contenttypes:defaultfilename:oncompletion:oncancellation:).md)
- [fileExporter(isPresented:documents:contentTypes:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:documents:contenttypes:oncompletion:oncancellation:).md)
- [fileExporter(isPresented:item:contentTypes:defaultFilename:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:item:contenttypes:defaultfilename:oncompletion:oncancellation:).md)
- [fileExporter(isPresented:items:contentTypes:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:items:contenttypes:oncompletion:oncancellation:).md)
- [fileExporterFilenameLabel(_:)](swiftui/view/fileexporterfilenamelabel(_:).md)
