---
title: gState()
framework: appkit
role: symbol
role_heading: Instance Method
path: appkit/nsview/gstate()
---

# gState()

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

## Declaration

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

## Discussion

Discussion A view object’s graphics state object is recreated from scratch whenever the view is focused, unless the allocateGState() method has been invoked. So if the view hasn’t been focused or hasn’t received the allocateGState() message, this method returns 0. Although applications rarely need to use the value returned by gState(), it can be passed to the few methods that take an object identifier as a parameter.

## See Also

### Methods

- [lockFocus()](appkit/nsview/lockfocus().md)
- [lockFocusIfCanDraw()](appkit/nsview/lockfocusifcandraw().md)
- [lockFocusIfCanDraw(in:)](appkit/nsview/lockfocusifcandraw(in:).md)
- [unlockFocus()](appkit/nsview/unlockfocus().md)
- [scroll(_:by:)](appkit/nsview/scroll(_:by:).md)
- [shouldDrawColor()](appkit/nsview/shoulddrawcolor().md)
- [allocateGState()](appkit/nsview/allocategstate().md)
- [setUpGState()](appkit/nsview/setupgstate().md)
- [renewGState()](appkit/nsview/renewgstate().md)
- [releaseGState()](appkit/nsview/releasegstate().md)
- [dragFile(_:from:slideBack:event:)](appkit/nsview/dragfile(_:from:slideback:event:).md)
- [dragPromisedFiles(ofTypes:from:source:slideBack:event:)](appkit/nsview/dragpromisedfiles(oftypes:from:source:slideback:event:).md)
