Search code examples
iphoneobjective-ccocoa-touchnotificationsnsnotifications

Where should I remove a notification observer?


I set up a notification observer in my view controller's init method like so:

[[NSNotificationCenter defaultCenter] 
                    addObserver:self
                    selector:@selector(saveState)
                    name:UIApplicationWillResignActiveNotification
                    object:nil];

Where is the best place to call removeObserver:name:object: for this notification. I'm currently calling it in my dealloc method, but wanted to know if that might cause problems.


Solution

  • No, you got it right. dealloc is the correct location to remove notification observers (unless you have some specific reason to need to remove the observer earlier).