---
title: UIGraphicsGetCurrentContext()
framework: uikit
role: symbol
role_heading: Function
path: uikit/uigraphicsgetcurrentcontext()
---

# UIGraphicsGetCurrentContext()

Returns the current graphics context.

## Declaration

```swift
func UIGraphicsGetCurrentContext() -> CGContext?
```

## Return Value

Return Value The current graphics context.

## Discussion

Discussion The current graphics context is nil by default. Prior to calling its drawRect: method, view objects push a valid context onto the stack, making it current. If you are not using a UIView object to do your drawing, however, you must push a valid context onto the stack manually using the UIGraphicsPushContext(_:) function. This function may be called from any thread of your app.

## See Also

### Graphics context primitives

- [UIGraphicsPushContext(_:)](uikit/uigraphicspushcontext(_:).md)
- [UIGraphicsPopContext()](uikit/uigraphicspopcontext().md)
- [UIGraphicsBeginImageContextWithOptions(_:_:_:)](uikit/uigraphicsbeginimagecontextwithoptions(_:_:_:).md)
- [UIRectClip(_:)](uikit/uirectclip(_:).md)
