I’m uisng addObserver:selector:name:object: in viewDidLoad.
And I’m using removeObserver:name:object: in viewWillDisappear:animated: to remove observer.
What will happen if I failed to remove observer by passing wrong parameter to removeObserver:name:object:?
(For example, observer isn’t removed if I pass wrong notification to parameter name or wrong object to object or Observer)
If the observer still not nil after calling removeObserver:name:object:, I can find out that removing observer failed because notificationSelector will being called.
But if the observer become nil after calling removeObserver:name:object:, I can not find out whether removing observer failed or not.
Will observers automatically removed when observer become nil?
Or does notification dispatch table of NSNotificationCenter became larger and larger and eventually the app become slow?
EDIT
When I use subclass of UIViewController object for observer, the app doesn’t crash after ViewController’s dealloc are called.
But when I use a object of other class, the app crashs after the object’s dealloc are called.
Update: From
-[NotificationCenter removeObserver:]:Old answer:
Observers are not removed automatically. From the NSNotificationCenter Class Reference:
You should therefore call
in your
deallocmethod if you are not 100% sure that the observer was not removed previously.