Ch 15 State Pattern - reason for using pattern in mirror pad not showing

Hello RayWenderlich team,

When going through the State Pattern chapter, it was noted that we use this pattern in MirrorPad so as to prevent users from adding new lines and points while the app is in a different state (i.e Animate). However after going through this chapter, and checking the final product, it appears that users are still able to add points and lines even while the app is animating. Any reason for this? It makes me unsure of why we even go through the trouble of using that pattern aside from refactoring. I tested using simulator.

Thanks!

@jrg.developer Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hey @crvillanueva thanks for your question! :]

There are two reasons that the state pattern is useful here:

  1. Yes, it’s a convenient way to fix the “bug” of allowing the user to draw while the app is animating.

  2. DrawView is doing way too much - the code is very complex already. If this were a real, large app, you’d likely struggle to both maintain and understand this class as you continued to add code to it over time.

In itself, reason 2 is definitely enough to justify this change. However, reason 1 is important too… you can imagine that this is a critical “shouldn’t be allowed” blocker issue, for example.

I just tested on the iPhone 8 simulator, and the final app works as expected. However, something has changed with the iPhone X/XR simulator, and this doesn’t actually prevent you from drawing while animating…! :scream:It also seems the drawing performance in the simulator is terrible… :frowning:

I’m not sure if this is a simulator bug, or if it will behave correctly on a real iPhone X/XR or not… I don’t have a real device to test using right now. However, I’m going to look into the issue further, and see if I can get it fixed in a future version of the book.

Thanks you bringing this issue up! Let me know if you have any other questions about this or anything else. :]