There are some APIs on iOS that are accessed via C and not ObjC objects. CoreGraphics for drawing (all of the CG*
functions) is one of the most important ones.
Direct drawing is typically done into a CGContextRef
, which represents a graphics context. UIKit keeps a stack of contexts for drawing (typically you won't interact much beyond the current context). This stack is accessed by global C functions because you can use them from anywhere. Typically, they are accessed from inside of drawRect:
, but you can use this stack elsewhere. Per the docs:
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.