iOS NSNotificationCenter Removing Observers

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Swift 2.3

//Remove observer for single notification
NSNotificationCenter.defaultCenter().removeObserver(self, name: "TestNotification", object: nil)
    
//Remove observer for all notifications
NotificationCenter.defaultCenter().removeObserver(self)

Swift 3

//Remove observer for single notification
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "TestNotification"), object: nil)

//Remove observer for all notifications
NotificationCenter.default.removeObserver(self)

Objective-C

//Remove observer for single notification
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"TestNotification" object:nil];
    
//Remove observer for all notifications
[[NSNotificationCenter defaultCenter] removeObserver:self];


Got any iOS Question?