ObserverBag
final class ObserverBag
A bag which can collect multiple notification tokens to de-register them on release of the bag.
-
Initializes a notification bag.
Declaration
Swift
public init(notificationCenter: NotificationCenter = .default)Parameters
notificationCenterThe
NotificationCenterinstance to keep a strong reference of it to remove the observers from it when the bag gets released. -
Adds a notification token to the bag.
Calls
removeObserveron the notification center with theobserveras parameter when this bag gets released.Declaration
Swift
public func add(_ observer: Any)Parameters
observerThe token to add.
View on GitHub