刪除觀察員

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];