---
title: NSGraphicsContext
framework: appkit
role: symbol
role_heading: Class
path: appkit/nsgraphicscontext
---

# NSGraphicsContext

An object that represents a graphics context.

## Declaration

```swift
class NSGraphicsContext
```

## Overview

Overview You can think of a graphics context as a destination to which drawing and graphics state operations are sent for execution. Each graphics context contains its own graphics environment and state. The NSGraphicsContext class is an abstract superclass for destination-specific graphics contexts. You obtain instances of concrete subclasses with the class methods current, init(attributes:), init(bitmapImageRep:), init(cgContext:flipped:), and init(window:). At any time there is the notion of the current context. The current context for the current thread may be set using current. Graphics contexts are maintained on a stack. You push a graphics context onto the stack by sending it a saveGraphicsState() message, and pop it off the stack by sending it a restoreGraphicsState() message. By sending restoreGraphicsState() to a graphics context object you remove it from the stack, and the next graphics context on the stack becomes the current graphics context.

## Topics

### Creating a Graphics Context

- [init(attributes:)](appkit/nsgraphicscontext/init(attributes:).md)
- [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)

### Managing the Current Context

- [current](appkit/nsgraphicscontext/current.md)
- [cgContext](appkit/nsgraphicscontext/cgcontext.md)
- [graphicsPort](appkit/nsgraphicscontext/graphicsport.md)

### Managing the Graphics State

- [restoreGraphicsState()](appkit/nsgraphicscontext/restoregraphicsstate()-swift.type.method.md)
- [restoreGraphicsState()](appkit/nsgraphicscontext/restoregraphicsstate()-swift.method.md)
- [saveGraphicsState()](appkit/nsgraphicscontext/savegraphicsstate()-swift.type.method.md)
- [saveGraphicsState()](appkit/nsgraphicscontext/savegraphicsstate()-swift.method.md)
- [setGraphicsState(_:)](appkit/nsgraphicscontext/setgraphicsstate(_:).md)

### Testing the Drawing Destination

- [currentContextDrawingToScreen()](appkit/nsgraphicscontext/currentcontextdrawingtoscreen().md)
- [isDrawingToScreen](appkit/nsgraphicscontext/isdrawingtoscreen.md)

### Getting Information About the Context

- [attributes](appkit/nsgraphicscontext/attributes.md)
- [NSGraphicsContext.AttributeKey](appkit/nsgraphicscontext/attributekey.md)
- [NSGraphicsContext.RepresentationFormatName](appkit/nsgraphicscontext/representationformatname.md)
- [isFlipped](appkit/nsgraphicscontext/isflipped.md)

### Flushing Graphics to the Context

- [flushGraphics()](appkit/nsgraphicscontext/flushgraphics().md)

### Configuring Rendering Options

- [compositingOperation](appkit/nsgraphicscontext/compositingoperation.md)
- [NSCompositingOperation](appkit/nscompositingoperation.md)
- [imageInterpolation](appkit/nsgraphicscontext/imageinterpolation.md)
- [NSImageInterpolation](appkit/nsimageinterpolation.md)
- [shouldAntialias](appkit/nsgraphicscontext/shouldantialias.md)
- [patternPhase](appkit/nsgraphicscontext/patternphase.md)

### Getting the Context for Rendering Core Image Objects

- [ciContext](appkit/nsgraphicscontext/cicontext.md)

### Managing Color Rendering

- [colorRenderingIntent](appkit/nsgraphicscontext/colorrenderingintent.md)
- [NSColorRenderingIntent](appkit/nscolorrenderingintent.md)

### Initializers

- [init(CGContext:flipped:)](appkit/nsgraphicscontext/init(cgcontext:flipped:)-4txqw.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
