Contents

addObserver(_:selector:name:object:suspensionBehavior:)

Adds an entry to the receiver’s dispatch table with a specific observer and suspended-notifications behavior, and optional notification name and sender.

Declaration

func addObserver(_ observer: Any, selector: Selector, name: NSNotification.Name?, object: String?, suspensionBehavior: DistributedNotificationCenter.SuspensionBehavior)

Parameters

  • observer:

    Object registering as an observer. Must not be nil.

  • selector:

    Selector that specifies the message the receiver sends notificationObserver to notify it of the notification posting. Must not be 0.

  • name:

    The name of the notification for which to register the observer; that is, only notifications with this name are delivered to the observer. When nil, the notification center doesn’t use a notification’s name to decide whether to deliver it to the observer.

  • object:

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

  • suspensionBehavior:

    Notification posting behavior when notification delivery is suspended.

Discussion

The receiver does not retain notificationObserver. Therefore, you should always send NotificationCenter/removeObserver(_:) or removeObserver(_:name:object:) to the receiver before releasing notificationObserver.

See Also

Related Documentation

Managing Observers