NotificationCenterObserving
public protocol NotificationCenterObserving
This helper protocol is introduced to make testing with NotificationCenter easier.
-
Adds an entry to the notification center’s dispatch table that includes a notification queue and a block to add to the queue, and an optional notification name and sender.
Declaration
Swift
func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocolParameters
nameThe name of the notification for which to register the observer; that is, only notifications with this name are used to add the block to the operation queue.
objThe object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer.
queueThe operation queue to which block should be added.
blockThe block to be executed when the notification is received.
Return Value
An opaque object to act as the observer.
-
Removes all entries specifying a given observer from the notification center’s dispatch table.
Declaration
Swift
func removeObserver(_ observer: Any)Parameters
observerThe observer to remove.
View on GitHub
NotificationCenterObserving Protocol Reference