What is the correct way of passing the drawing context to another method in the same class from drawRect()
?
do you just pass it like this?
drawMoreStuff:(CGContextRef)context
or do you use the functions:
UIGraphicsGetCurrentContext();
and CGContextRestoreGState(ctx);
at the beginning and end of the function respectively ?
Well, a context that is passed to a function may not always be the same as the current context, so the best way would be like in your first example.
- (void)drawMoreStuff:(CGContextRef)context {
Depending on your function though, you would use the current context if you have a function like:
- (void)drawMoreStuffToCurrentContext {
I use blocks for that aim, this question and answer will give you enough about how to go. Especially accepted answer gives what you want.