Abhinav Abhinav - 1 year ago 93
Swift Question

Removing all notification observer from a single place

I want to remove a notification observer and I am using the method:

removeObserver: name:@"myNotification" object:nil

for this. Now there are many observers who are listening to this notification and I want to remove all of them in one shot from a centralized place. Can I pass 'nil' in first parameter and it will remove all observers who are listening to myNotification?

Answer Source

You can remove an object from the notification center all together which means no notifications will get triggered. For example, when I have a view controller that has registered for notifications, I include this line in my dealloc.

[[NSNotificationCenter defaultCenter] removeObserver:self];

This is at the object level...so it will unregister for many notifications. It won't unregister for one notification in many objects.

Hope I understood your question correctly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download