UIGraphicsBeginImageContextWithOptions and Multithreading UIGraphicsBeginImageContextWithOptions and Multithreading multithreading multithreading

UIGraphicsBeginImageContextWithOptions and Multithreading


So, after a couple of days of investigating, how come manipulating the UIKit context is thread-safe and yet you don't seem to be able to create one in a thread other than the main because UIGraphicsBeginImageContextWithOptions "should be called only on the main thread", but still doing so works perfectly fine and after reading some small posts on the subject and discussing it with other guys on Apple's developer forums I can clearly state that, what's said in the documentation about UIGraphicsBeginImageContextWithOptions, UIGraphicsPushContext and UIGraphicsPopContext is WRONG and those methods could be called and the context used in another thread without problems. So UIGraphicsBeginImageContextWithOptions, UIGraphicsPushContext and UIGraphicsPopContext are thread-safe.


Partial answer: Use UIGraphicsPushContext to push your own CG context to the top of the "UIKit context" stack and everything (from that thread, as I interpret Apple's documentation) will paint to that. Don't forget to use UIGraphicsPopContext to pop it from the UIKit context stack.

This applies to all UIKit drawing operations; for example drawing UIImages, like you asked. Push a context, draw, then pop the context.