iOS unable to remove Notification observer. Deinit not getting called

I've found the removeObserver() only works if you use this version of addObserver()

notification.addObserver(self, selector:#selector(self.handleUpdateTimer), name: Notification.Name(rawValue: "TimerUpdated"), object: nil)

I'm guessing with the original version you aren't actually indicating who the observer is.


As @Spads said you can use

NotificationCenter.default.addObserver(self, selector: #selector(subscribeToNotifications), name: NSNotification.Name(rawValue: "TimerUpdate"), object: nil)

or the one you already have. you can remove your notification by it's name or it's reference

NotificationCenter.default.removeObserver(self, name: "TimerUpdate", object: nil)

if you declared your notification at the top of your class then you can directly pass the reference of your notification to be removed in your case notification

 NotificationCenter.default.removeObserver(notification)