<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSGraphicsContext/init(attributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSGraphicsContext(cm)graphicsContextWithAttributes:"
  },
  "title" : "init(attributes:)"
}
-->

# init(attributes:)

Creates a graphics context using the specified attributes.

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

## Parameters

`attributes`

A dictionary of values associated with the keys described in [`NSGraphicsContext.AttributeKey`](/documentation/AppKit/NSGraphicsContext/AttributeKey). The attributes specify such things as representation format and destination.

## Return Value

A new [`NSGraphicsContext`](/documentation/AppKit/NSGraphicsContext) object, or `nil` if the object could not be created.

## 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`](/documentation/AppKit/NSPrintOperation) class to set up the printing environment needed to generate that type of information.

---

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)