<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuickLook",
  "identifier" : "/documentation/QuickLook/QLPreviewingController/preparePreviewOfFile(at:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Quick Look"
    ],
    "preciseIdentifier" : "c:objc(pl)QLPreviewingController(im)preparePreviewOfFileAtURL:completionHandler:"
  },
  "title" : "preparePreviewOfFile(at:completionHandler:)"
}
-->

# preparePreviewOfFile(at:completionHandler:)

```
optional func preparePreviewOfFile(at url: URL, completionHandler handler: @escaping @Sendable ((any Error)?) -> Void)
```

```
optional func preparePreviewOfFile(at url: URL) async throws
```

## Parameters

`url`

The URL of the file the user is about to preview.

`handler`

The completion handler should be called whenever the view is ready to be displayed. A loading spinner will be shown until the handler is called.
It can be called asynchronously after the method has returned.

## Discussion\abstract Use this method to prepare the content of the view controller with the given file URL.
\discussion This method will be called only once. It will be called in the main thread before presenting the view controller.
Heavy work potentially blocking the main thread should be avoided in this method.

---

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)