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
notificationCenter
The
NotificationCenter
instance 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
removeObserver
on the notification center with theobserver
as parameter when this bag gets released.Declaration
Swift
public func add(_ observer: Any)
Parameters
observer
The token to add.