<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PhotoKit",
  "identifier" : "/documentation/Photos/PHAssetResourceManager/writeData(for:toFile:options:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Photos"
    ],
    "preciseIdentifier" : "c:objc(cs)PHAssetResourceManager(im)writeDataForAssetResource:toFile:options:completionHandler:"
  },
  "title" : "writeData(for:toFile:options:completionHandler:)"
}
-->

# writeData(for:toFile:options:completionHandler:)

Requests the underlying data for the specified asset resource, to be asynchronously written to a local file.

```
func writeData(for resource: PHAssetResource, toFile fileURL: URL, options: PHAssetResourceRequestOptions?, completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

## Parameters

`resource`

The asset resource for which to request data.

`fileURL`

A URL identifying the local filename at which to write the asset resource’s data.

`options`

Options specifying how Photos should handle the request and notify your app of progress. For details, see [`PHAssetResourceRequestOptions`](/documentation/Photos/PHAssetResourceRequestOptions).

`completionHandler`

A block that photos calls after the request has been fulfilled or has failed.

    The block takes a single parameter:

- error: If the request has failed, an `NSError` object describing the failure; otherwise `nil`.

## Discussion

When you call this method, Photos begins asynchronously reading the underlying data for the asset resource. Depending on the options you specify and the current state of the asset, Photos may download asset data from the network.

While reading (or downloading) asset resource data, Photos progressively writes the data into the specified file. After writing all of the data, or if an error prevents reading all of the data, Photos calls your `completionHandler` block.

> Note:
> Photos calls your `completionHandler` block on an arbitrary serial queue. To update the UI in response to these events, dispatch to the main queue.

---

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)