Instance Method

removeObserver:

Removes all entries specifying a given observer from the notification center's dispatch table.

Declaration

- (void)removeObserver:(id)observer;

Parameters

observer

The observer to remove.

Discussion

If your app targets iOS 9.0 and later or macOS 10.11 and later, you don't need to unregister an observer in its dealloc method. Otherwise, you should call this method or removeObserver:name:object: before observer or any object specified in addObserverForName:object:queue:usingBlock: or addObserver:selector:name:object: is deallocated.

You shouldn't use this method to remove all observers from a long-lived object, because your code may not be the only code adding observers that involve the object.

The following example illustrates how to unregister someObserver for all notifications for which it had previously registered. This is safe to do in the dealloc method, but should not otherwise be used (use removeObserver:name:object: instead).

[[NSNotificationCenter defaultCenter] removeObserver:someObserver];

See Also

Adding and Removing Notification Observers

addObserverForName:object:queue:usingBlock:

Adds an entry to the notification center's dispatch table that includes a notification queue and a block to add to the queue, and an optional notification name and sender.

addObserver:selector:name:object:

Adds an entry to the notification center's dispatch table with an observer and a notification selector, and an optional notification name and sender.

removeObserver:name:object:

Removes matching entries from the notification center's dispatch table.