Does removeObserver() remove all observers? Does removeObserver() remove all observers? swift swift

Does removeObserver() remove all observers?


Yes, the removeObserver(self) call will remove all observers that you added using addObserver:selector:name:object: with an observer of self, regardless of the notification name, object, or selector you specified.

It is a bad idea to use the removeObserver(self) method anywhere but in your object's deinit method, because some system classes (or subclasses of objects that you define) may have added observers that you don't know about. That method call is a "scorched earth" call the removes ALL observers from the object.

Instead you should call removeObserver:name:object: and remove only the observers that you added.


Removes all the entries specifying a given observer from the receiver’s dispatch table.https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/index.html#//apple_ref/occ/instm/NSNotificationCenter/removeObserver:

So I guess it'll remove all observers only when all are same as specified by the parameter.