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

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

Adds an entry to the notification center’s dispatch table with an observer, a selector, and an optional notification name and sender.

```
func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name?, object anObject: String?)
```

## Parameters

`observer`

An object registering as an observer.

`aSelector`

A selector that the notification center sends `notificationObserver` to notify when posting the notification.

`aName`

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.

`anObject`

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.

## Discussion

This method calls [`addObserver(_:selector:name:object:suspensionBehavior:)`](/documentation/Foundation/DistributedNotificationCenter/addObserver(_:selector:name:object:suspensionBehavior:)), passing [`DistributedNotificationCenter.SuspensionBehavior.coalesce`](/documentation/Foundation/DistributedNotificationCenter/SuspensionBehavior/coalesce) for `suspensionBehavior`.

---

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)