What I want to know is should I pass the CGContextRef obtained from UIGraphicsGetCurrentContext() as a parameter to each function, or can I call it at the beginning of each function ? The latter option seems more suitable for me, but I want to know if there is a lot of performance loss?
I suggest that if you don’t save and restore state, you can use UIGraphicsGetCurrentContext(). However, if you are indeed saving state, then you should pass this , Because it will be easier to read your code.
I think this is a style issue…
I am building a UIView that defines the drawRect function. This is a fairly complex view that requires drawing many different items. I basically break it down into a function for each item that needs to be drawn.
I think What I know is should I pass the CGContextRef obtained from UIGraphicsGetCurrentContext() as a parameter to each function, or can I call it at the beginning of each function? The latter option seems more suitable for me, but I want to know if there is a lot of performance loss?
It is the same unless you are saving/restoring the context. In any case, getting the context from this method will most likely never become a bottleneck.
I suggest that if you don’t save and restore the state, you can use UIGraphicsGetCurrentContext(). However, if you are indeed saving the state, then you should pass this because it will be easier to read your code. < /p>
I think this is a style issue…