<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.10.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/gState()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(im)gState"
  },
  "title" : "gState()"
}
-->

# gState()

Returns the identifier for the view’s graphics state object, or 0 if the view doesn’t have a graphics state object.

```
func gState() -> Int
```

## Discussion

A view object’s graphics state object is recreated from scratch whenever the view is focused, unless the [`allocateGState()`](/documentation/AppKit/NSView/allocateGState()) method has been invoked. So if the view hasn’t been focused or hasn’t received the [`allocateGState()`](/documentation/AppKit/NSView/allocateGState()) message, this method returns 0.

Although applications rarely need to use the value returned by [`gState()`](/documentation/AppKit/NSView/gState()), it can be passed to the few methods that take an object identifier as a parameter.

---

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)