[quote=“takeiteasybrah”]When I did the challenge I saved the graphics state just before I set the shadow using the CGContextSaveGState function and then restored the state after drawing the text using CGContextRestoreGState. This reverted my context’s graphics state to the state it was in before I set the shadow. Your approach was to disable the shadow by setting its color to NULL in the CGContextSetShadowWithColor function. Both solutions provide the same result.
For this example there doesn’t seem to be much benefit for one approach over the other. Where I think CGContextSaveGState and CGContextRestoreGState might come in handy is when you make multiple changes to the graphics state and want to restore back to an earlier version. The documentation for the CGContextSaveGState lists the different graphics state parameters that are saved by this method and there are quite a few.[/quote]
I think this explains it perfectly, and thank you for this answer.
The authors want you to nail down thinking in terms of contexts here. So in your program, you’re going to change the context to add shadows to everything drawn, and write some text. Then, they very clearly tell you after that happens, they want you to do some non-shadowed drawing.
You could just ignore the whole concept of contexts and try and undo what you just did with the shadowing.
But what they doubtless intended for you to do was to realize, “Hey, if I save the context BEFORE I start shadowing and doing all this text stuff, I can bring it right back without worrying about all the changes I just made.”
If you think about it for a minute, NOT saving the context you were working in would be a real PITA if you do some really complicated drawing, and then have to try to undo everything you just did. That’s just a recipe for buggy and tedious programming.