<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/DistributedNotificationCenter/addObserver(_:selector:name:object:suspensionBehavior:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDistributedNotificationCenter(im)addObserver:selector:name:object:suspensionBehavior:"
  },
  "title" : "addObserver(_:selector:name:object:suspensionBehavior:)"
}
-->

# 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.

```
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:)`](/documentation/Foundation/DistributedNotificationCenter/removeObserver(_:name:object:)) to the receiver before releasing `notificationObserver`.

## See Also

[`postNotificationName(_:object:userInfo:deliverImmediately:)`](/documentation/Foundation/DistributedNotificationCenter/postNotificationName(_:object:userInfo:deliverImmediately:))

Creates a notification with information and an immediate-delivery specifier, and posts it to the receiver.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)