Pattern: Unneeded NotificationCenter
removal
Issue: -
Observers are automatically unregistered on dealloc (iOS 9 / macOS 10.11) so you should’t call removeObserver(self)
in the deinit.
Examples of correct code:
class Example {
deinit {
NotificationCenter.default.removeObserver(someOtherObserver)
}
}
class Example {
func removeObservers() {
NotificationCenter.default.removeObserver(self)
}
}
class Example {
deinit {
cleanup()
}
}
Examples of incorrect code:
class Foo {
deinit {
NotificationCenter.default.removeObserver(↓self)
}
}
class Foo {
deinit {
NotificationCenter.default.removeObserver(↓self,
name: UITextView.textDidChangeNotification, object: nil)
}
}