<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuickLookThumbnailing",
  "identifier" : "/documentation/QuickLookThumbnailing/QLThumbnailGenerator/generateBestRepresentation(for:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Quick Look Thumbnailing"
    ],
    "preciseIdentifier" : "c:objc(cs)QLThumbnailGenerator(im)generateBestRepresentationForRequest:completionHandler:"
  },
  "title" : "generateBestRepresentation(for:completion:)"
}
-->

# generateBestRepresentation(for:completion:)

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

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

## 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:

- `thumbnail`: The most representative version of the requested thumbnail or `nil` if `QLThumbnailGenerator` was unable to generate a thumbnail.
- `error`: An error object that indicates why the thumbnail generation failed, or `nil` if the thumbnail generation succeeded.

## 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:
> 
> ```swift
> func generateBestRepresentation(for request: QLThumbnailGenerator.Request) async throws -> QLThumbnailRepresentation
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

---

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)