Maybe the title does not provide a good description so please read the following.
I have a notification that is set to listen to an event:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.checkIfNotificationsWereTurnedOnAfterAlertShowing), name: UIApplicationWillEnterForegroundNotification, object: UIApplication.sharedApplication())
Then I want to remove observer on this notification. I found that I need to use deinit like this:
deinit {
NSNotificationCenter.defaultCenter().removeObserver(UIApplicationWillEnterForegroundNotification)
print("deinit")
}
But the problem is that when i close the view controller, the program never executes deinit function. In this answer i found that it could be due to strong reference.
I checked many links but was not able to find how to declare a weak reference for a notification. So how can I declare a weak notification?
Hope my question is clear.
Looking forward for your help.