---
title: "draw(in:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsimagerep/draw(in:)"
---

# draw(in:)

Draws the image, scaling it (as needed) to fit the specified rectangle.

## Declaration

```swift
func draw(in rect: NSRect) -> Bool
```

## Parameters

- `rect`: The rectangle in the current coordinate system in which to draw the image.

## Return Value

Return Value true if the image was successfully drawn; otherwise, false. If the size of the image has not yet been set, this method returns false immediately.

## Discussion

Discussion This method sets the origin of the current coordinate system to the origin of the specified rectangle before invoking the receiver’s draw() method. If the rectangle size is different from the image’s native size, this method adjusts the coordinate transform, causing the image to be scaled appropriately.  After the draw method returns, the coordinate system changes are undone, restoring the original graphics state.

## See Also

### Drawing Images

- [draw()](appkit/nsimagerep/draw().md)
- [draw(at:)](appkit/nsimagerep/draw(at:).md)
- [draw(in:from:operation:fraction:respectFlipped:hints:)](appkit/nsimagerep/draw(in:from:operation:fraction:respectflipped:hints:).md)
- [NSImageRep.HintKey](appkit/nsimagerep/hintkey.md)
