NotificationCenter

extension NotificationCenter
  • Adds an entry to the notification center’s dispatch table for a CheetahNotification that includes the sender, a notification queue, and a block to add to the queue.

    This creates a Notification using the CheetahNotification.name, passes it to addObserver(forName:, object:, queue:, using:), and returning its result.

    Declaration

    Swift

    public func addObserver(for notification: CheetahNotification,
                            object: Any?,
                            queue: OperationQueue?,
                            using: @escaping (_ notification: Notification) -> Void) -> NSObjectProtocol

    Parameters

    notification

    The notification.

    object

    The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer. If you pass nil, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.

    queue

    The operation queue to which block should be added. If you pass nil, the block is run synchronously on the posting thread.

    using

    The block to be executed when the notification is received. The block is copied by the notification center and (the copy) held until the observer registration is removed. The block takes one argument:

    notification

    The notification.

    Return Value

    An opaque object to act as the observer.