NotificationObserver
public final class NotificationObserver <V, S: AnyObject>
An instance of NotificationObserver is responsible for observing notifications.
Warning
When an observer is initialized, it will immediately begin listening for its specified notification by registering with the specified notification center. To stop listening, dealloc the observer by setting it tonil.
-
The closure to be called when an
NSNotificationis received.Declaration
Swift
public typealias NotificationClosure = (notification: NSNotification) -> VoidParameters
notificationThe notification received.
-
The closure to be called when a
Notificationis received.Declaration
Swift
public typealias ValueSenderClosure = (value: V, sender: S?) -> VoidParameters
valueThe data sent with the notification.
senderThe object that sent the notification, or
nilif the notification is not associated with a specific sender.
-
Constructs a new
NotificationObserverinstance and immediately registers to begin observing the specifiednotification.Warning
To unregister this observer and end listening for notifications, dealloc the object by setting it to
nil.Declaration
Swift
public convenience init(_ notification: Notification<V, S>, queue: NSOperationQueue? = nil, center: NSNotificationCenter = .defaultCenter(), handler: ValueSenderClosure)Parameters
notificationThe notification for which to register the observer.
queueThe operation queue to which
handlershould be added. Ifnil(the default), the block is run synchronously on the posting thread.centerThe notification center from which the notification should be dispatched. The default is
NSNotificationCenter.defaultCenter().handlerThe closure to execute when the notification is received.
Return Value
A new
NotificationObserverinstance. -
Constructs a new
NotificationObserverinstance and immediately registers to begin observing the specifiednotification.Warning
To unregister this observer and end listening for notifications, dealloc the object by setting it to
nil.Declaration
Swift
public init(_ notification: Notification<V, S>, queue: NSOperationQueue? = nil, center: NSNotificationCenter = .defaultCenter(), handler: NotificationClosure)Parameters
notificationThe notification for which to register the observer.
queueThe operation queue to which
handlershould be added. Ifnil(the default), the block is run synchronously on the posting thread.centerThe notification center from which the notification should be dispatched. The default is
NSNotificationCenter.defaultCenter().handlerThe closure to execute when the notification is received.
Return Value
A new
NotificationObserverinstance.
View on GitHub
NotificationObserver Class Reference