Search code examples
iosios5nsnotificationcenternsnotifications

Where will I unregister NSNotification?


I often registered NSNotification in a viewDidLoad and unregistered in a dealloc. We don't have dealloc in ios 5. Where will I unregister NSNotification?


Solution

  • You can still use dealloc in ARC (I assume this is what you mean by iOS 5) - just define the method as before. Just don't call [super dealloc].

    - (void) dealloc {
       // unregister and clean up.
       // NO SUPER!
    }
    

    I use this pattern a lot - especially when checking for leaks it's handy to put an NSLog in there.