<!--
{
  "availability" : [
    "iOS: 18.2.0 -",
    "iPadOS: 18.2.0 -",
    "macCatalyst: 18.2.0 -",
    "macOS: 15.2.0 -",
    "tvOS: 18.2.0 -",
    "visionOS: 2.2.0 -",
    "watchOS: 11.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreTransferable",
  "identifier" : "/documentation/CoreTransferable/Transferable/withExportedFile(contentType:fileHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Transferable",
      "CoreTransferable"
    ],
    "preciseIdentifier" : "s:16CoreTransferable0B0PAAE16withExportedFile11contentType11fileHandlerqd__07UniformG11Identifiers6UTTypeVSg_qd__10Foundation3URLVYaKXEtYaKlF"
  },
  "title" : "withExportedFile(contentType:fileHandler:)"
}
-->

# withExportedFile(contentType:fileHandler:)

Using the type’s `Transferable` conformance implementation,
exports a value by writing it to disk and removes when not needed.

```
func withExportedFile<Result>(contentType: UTType?, fileHandler: (URL) async throws -> Result) async throws -> Result
```

## Parameters

`contentType`

A content type of the requested file.
If the content type is not provided, CoreTransferable creates
a file from the first `TransferRepresentation` that supports export.

`fileHandler`

A closure that accepts a file URL as a parameter.
The file is written to a temporary destination and removed
after the closure returns.

## Discussion

This converts a [`Transferable`](/documentation/CoreTransferable/Transferable) item into a temporary file, and
removes it after `fileHandler` closure returns. The default implementation
of this function is available to all types that conform
to `Transferable` protocol.

---

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)