---
title: "addObserver(_:selector:name:object:suspensionBehavior:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/distributednotificationcenter/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.

## Declaration

```swift
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

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

- [postNotificationName(_:object:userInfo:deliverImmediately:)](foundation/distributednotificationcenter/postnotificationname(_:object:userinfo:deliverimmediately:).md)

### Managing Observers

- [addObserver(_:selector:name:object:)](foundation/distributednotificationcenter/addobserver(_:selector:name:object:).md)
- [removeObserver(_:name:object:)](foundation/distributednotificationcenter/removeobserver(_:name:object:).md)
