Observer pattern is common on iOS platform, you use observers in NSNotificationCenter and in Key Value Observing. You need to remember to unregister before you release your observer object, if you don’t you are going to have crashes.For example notification get posted and system tries to inform deallocated object about it, and it crashes.
I’ve created a simple category that takes care of this problem, whenever an object that is observing (NSNotification or KVO) it’s going to be deallocated, it will be unregistered in those systems. The category that I’ve created doesn’t require you to call special methods or do anything fancy. Just include it and you have auto-removal working. It works on both ARC and non ARC code without any settings…
You can grab it from GitHub or read more to learn about few tricks I’ve used to make it happen.
Read on →