---
title: "bestRepresentation(for:context:hints:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsimage/bestrepresentation(for:context:hints:)"
---

# bestRepresentation(for:context:hints:)

Returns the best representation of the image for the specified rectangle using the provided hints.

## Declaration

```swift
func bestRepresentation(for rect: NSRect, context referenceContext: NSGraphicsContext?, hints: [NSImageRep.HintKey : Any]?) -> NSImageRep?
```

## Parameters

- `rect`: The area of the image to return.
- `referenceContext`: A graphics context. This value can be nil.
- `hints`: An optional dictionary of hints that provide more context for selecting or generating a CGImage, and may override properties of the referenceContext. See Image Hint Dictionary Keys for a summary of the possible key-value pairs.

## Return Value

Return Value The image representation that most closely matches the specified criteria.

## See Also

### Working with Representations of Images

- [addRepresentation(_:)](appkit/nsimage/addrepresentation(_:).md)
- [addRepresentations(_:)](appkit/nsimage/addrepresentations(_:).md)
- [representations](appkit/nsimage/representations.md)
- [removeRepresentation(_:)](appkit/nsimage/removerepresentation(_:).md)
- [NSImageRep.HintKey](appkit/nsimagerep/hintkey.md)
- [NSImage.LayoutDirection](appkit/nsimage/layoutdirection.md)
