I recently looked into some swift code and I found this: adding the observer and then removing it right after. What's the logic behind that?
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "displayPushMessage:", name: "displayMessage", object: nil)
}
//adding the observer and removing it right after whhy?? where is the logic
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self, name: "displayMessage", object: nil)
}
func displayPushMessage (notification:NSNotification) {