---
title: "preparePreviewOfFile(at:completionHandler:)"
framework: QuickLook UI
role: symbol
role_heading: Instance Method
platforms: [macOS 10.10+]
path: "quicklookui/qlpreviewingcontroller/preparepreviewoffile(at:completionhandler:)"
---

# preparePreviewOfFile(at:completionHandler:)

Prepares the preview of a file at the specified file’s URL.

## 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 to preview.
- `handler`: A completion handler that notifies the platform that a preview is available. The operating system shows a loading spinner, so call the handler as soon as possible. You can call the completion handler asynchronously after returning from the callback.

## Discussion

Discussion The operating system calls this method only once from the main thread before it presents the previewing controller. To avoid blocking the main thread, don’t perform long-running or resource-intensive work. When preparing and displaying the view controller, avoid holding open a file descriptors while the user is previewing the file.

## See Also

### Instance Methods

- [preparePreviewOfSearchableItem(identifier:queryString:completionHandler:)](quicklookui/qlpreviewingcontroller/preparepreviewofsearchableitem(identifier:querystring:completionhandler:).md)
- [providePreview(for:completionHandler:)](quicklookui/qlpreviewingcontroller/providepreview(for:completionhandler:).md)
