---
title: "generateBestRepresentation(for:completion:)"
framework: quicklookthumbnailing
role: symbol
role_heading: Instance Method
path: "quicklookthumbnailing/qlthumbnailgenerator/generatebestrepresentation(for:completion:)"
---

# generateBestRepresentation(for:completion:)

Generates the best possible thumbnail representation for a file and calls a handler upon completion.

## Declaration

```swift
func generateBestRepresentation(for request: QLThumbnailGenerator.Request, completion completionHandler: @escaping @Sendable (QLThumbnailRepresentation?, (any Error)?) -> Void)
```

```swift
func generateBestRepresentation(for request: QLThumbnailGenerator.Request) async throws -> QLThumbnailRepresentation
```

## Parameters

- `request`: The request that contains information about the thumbnail that you want to create.
- `completionHandler`: The completion handler to call when the thumbnail generation completes. It is always called when QLThumbnailGenerator finishes the generation of a requested thumbnail. The completion handler takes the following parameters:

## Mentioned in

Creating Quick Look Thumbnails to Preview Files in Your App

## Discussion

Discussion important: You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration: func generateBestRepresentation(for request: QLThumbnailGenerator.Request) async throws -> QLThumbnailRepresentation For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously.

## See Also

### Generating a Thumbnail

- [generateRepresentations(for:update:)](quicklookthumbnailing/qlthumbnailgenerator/generaterepresentations(for:update:).md)
- [QLThumbnailGenerator.Request](quicklookthumbnailing/qlthumbnailgenerator/request.md)
