---
title: "init(size:flipped:drawingHandler:)"
framework: appkit
role: symbol
role_heading: Initializer
path: "appkit/nscustomimagerep/init(size:flipped:drawinghandler:)"
---

# init(size:flipped:drawingHandler:)

Initializes a representation of an image of the specified size and flipped status, using a block to draw its content.

## Declaration

```swift
init(size: NSSize, flipped drawingHandlerShouldBeCalledWithFlippedContext: Bool, drawingHandler: @escaping (NSRect) -> Bool)
```

## Parameters

- `size`: The size of the image.
- `drawingHandlerShouldBeCalledWithFlippedContext`: doc://com.apple.documentation/documentation/Swift/true if the drawing handler should be called with a flipped graphics context; otherwise doc://com.apple.documentation/documentation/Swift/false.
- `drawingHandler`: A block that draws the image representation content in the provided graphics context. The block may be invoked whenever and on whatever thread the image itself is drawn on. Care should be taken to ensure that all state accessed within the drawingHandler block is done so in a thread safe manner. This Block replaces the doc://com.apple.appkit/documentation/AppKit/NSImage/lockFocus() and doc://com.apple.appkit/documentation/AppKit/NSImage/unlockFocus() technique of creating drawing content. The block is invoked at draw time, the drawing can be adjusted to suit the destination’s pixel density, color space, and other properties.

## Return Value

Return Value An initialized NSCustomImageRep object, or nil if the object could not be initialized.

## Discussion

Discussion Using the this method ensures you’ll get correct results under standard and high resolution. Like other non-bitmap image rep types, drawing is cached as appropriate for the destination context. Practically speaking, the drawingHandler block will be invoked the first time the image is drawn to a particular type of destination (1x or 2x screen, for example). Subsequent drawing operations to the same type of destination will reuse the previously generated bitmap.

## See Also

### Related Documentation

- [drawingHandler](appkit/nscustomimagerep/drawinghandler.md)

### Creating Representations of Images in Custom Formats

- [init(draw:delegate:)](appkit/nscustomimagerep/init(draw:delegate:).md)
