---
title: "preparePreviewOfFile(at:completionHandler:)"
framework: quicklook
role: symbol
role_heading: Instance Method
path: "quicklook/qlpreviewingcontroller/preparepreviewoffile(at:completionhandler:)"
---

# preparePreviewOfFile(at:completionHandler:)

## Declaration

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

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

Discussion Use this method to prepare the content of the view controller with the given file URL. 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.
