Question

From Apple iOS Documentation #UIGraphicsGetCurrentContext: "In iOS 4 and later, you may call this function from any thread of your app."

Also, why is the method call in C function format UIGraphicsGetCurrentContext() and not Objective-C message format [UIView UIGraphicsGetCurrentContext]?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top