---
title: "init(attributes:)"
framework: appkit
role: symbol
role_heading: Initializer
path: "appkit/nsgraphicscontext/init(attributes:)"
---

# init(attributes:)

Creates a graphics context using the specified attributes.

## Declaration

```swift
init?(attributes: [NSGraphicsContext.AttributeKey : Any] = [:])
```

## Parameters

- `attributes`: A dictionary of values associated with the keys described in doc://com.apple.appkit/documentation/AppKit/NSGraphicsContext/AttributeKey. The attributes specify such things as representation format and destination.

## Return Value

Return Value A new NSGraphicsContext object, or nil if the object could not be created.

## Discussion

Discussion Use this method to create a graphics context for a window or bitmap destination. If you want to create a graphics context for a PDF or PostScript destination, do not use this method; instead, use the NSPrintOperation class to set up the printing environment needed to generate that type of information.

## See Also

### Creating a Graphics Context

- [init(bitmapImageRep:)](appkit/nsgraphicscontext/init(bitmapimagerep:).md)
- [init(cgContext:flipped:)](appkit/nsgraphicscontext/init(cgcontext:flipped:)-9cbad.md)
- [init(window:)](appkit/nsgraphicscontext/init(window:).md)
- [init(graphicsPort:flipped:)](appkit/nsgraphicscontext/init(graphicsport:flipped:).md)
