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

# fileExporter(isPresented:item:contentTypes:defaultFilename:onCompletion:onCancellation:)

Presents a system dialog allowing the user to export
a `Transferable` item to a file on disk.

```
nonisolated func fileExporter<T>(isPresented: Binding<Bool>, item: T?, contentTypes: [UTType] = [], defaultFilename: String? = nil, onCompletion: @escaping (Result<URL, any Error>) -> Void, onCancellation: @escaping () -> Void = { }) -> some View where T : Transferable
```

## Parameters

`isPresented`

A binding to whether the dialog should be shown.

`item`

The item to be saved on disk.

`contentTypes`

The optional content types to use for the exported
file. If empty, SwiftUI uses the content types from the
`transferRepresentation` property provided for `Transferable`
conformance.

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

`onCancellation`

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

## Discussion

In order for the dialog to appear, `isPresented` must be set to `true`.
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.

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

```
struct ExportPhotoButton: View {
    @State private var isExporterPresented = false
    var photo: Photo

    var body: some View {
        Button("Export Photo") {
            isExporterPresented = true
        }
        .fileExporter(
            isPresented: $isExporterPresented,
            item: photo,
            defaultFilename: "exported photo"
        ) { result in
            switch result {
            case .success(let url):
                print("Saved to \(url)")
            case .failure(let error):
                print(error)
            }
        } onCancellation: {
            print("Export cancelled")
        }
    }
}

struct Photo: Transferable { ... }
```

To further configure the dialog’s appearance and behavior, use these
view modifiers: [`fileDialogDefaultDirectory(_:)`](/documentation/SwiftUI/View/fileDialogDefaultDirectory(_:)),
[`fileDialogConfirmationLabel(_:)`](/documentation/SwiftUI/View/fileDialogConfirmationLabel(_:)), [`fileDialogMessage(_:)`](/documentation/SwiftUI/View/fileDialogMessage(_:)),
[`fileDialogBrowserOptions(_:)`](/documentation/SwiftUI/View/fileDialogBrowserOptions(_:)),
[`fileExporterFilenameLabel(_:)`](/documentation/SwiftUI/View/fileExporterFilenameLabel(_:)), and
[`fileDialogCustomizationID(_:)`](/documentation/SwiftUI/View/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)