<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSGraphicsContext/restoreGraphicsState()-swift.method",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSGraphicsContext(im)restoreGraphicsState"
  },
  "title" : "restoreGraphicsState()"
}
-->

# restoreGraphicsState()

Removes the context’s graphics state from the top of the graphics state stack and makes the next graphics state the current graphics state.

```
func restoreGraphicsState()
```

## Discussion

This method must have been preceded with a [`saveGraphicsState()`](/documentation/AppKit/NSGraphicsContext/saveGraphicsState()-swift.method) message to add the graphics state to the stack. Invocations of [`saveGraphicsState()`](/documentation/AppKit/NSGraphicsContext/saveGraphicsState()-swift.method) and [`restoreGraphicsState()`](/documentation/AppKit/NSGraphicsContext/restoreGraphicsState()-swift.method) methods may be nested.

Restoring the graphics state restores such attributes as the current drawing style, transformation matrix, color, and font of the original graphics state.

---

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)