Pattern: Unsafe NotificationCenter
detachment
Issue: -
Warns when an object removes itself as an observer to all notifications. This can be a problem if a superclass or a subclass wants to keep observing some notifications.
An object should only remove itself as an observer in deinit
.
Examples of correct code:
class Foo {
deinit {
NotificationCenter.default.removeObserver(self)
}
}
class Foo {
func bar() {
NotificationCenter.default.removeObserver(otherObject)
}
}
Examples of incorrect code:
class Foo {
func bar() {
↓NotificationCenter.default.removeObserver(self)
}
}