---
title: DistributedNotificationCenter
framework: foundation
role: symbol
role_heading: Class
path: foundation/distributednotificationcenter
---

# DistributedNotificationCenter

A notification dispatch mechanism that enables the broadcast of notifications across task boundaries.

## Declaration

```swift
class DistributedNotificationCenter
```

## Overview

Overview A DistributedNotificationCenter instance broadcasts NSNotification objects to objects in other tasks that have registered for the notification with their task’s default distributed notification center. Principal Attributes Notification dispatch table. See “Class at a Glance” > “Principal Attributes” in NotificationCenter for information about the dispatch table. In addition to the notification name and sender, dispatch table entries for distributed notification centers specify when the notification center delivers notifications to its observers. See the postNotificationName(_:object:userInfo:deliverImmediately:) method, Suspending and Resuming Notification Delivery, and DistributedNotificationCenter.SuspensionBehavior for details. Commonly Used Methods Overview Each task has a default distributed notification center that you access with the default() class method. There may be different types of distributed notification centers. Currently there is a single type—NSLocalNotificationCenterType. This type of distributed notification center handles notifications that can be sent between tasks on a single computer. For communication between tasks on different computers, use Distributed Objects Programming Topics. Posting a distributed notification is an expensive operation. The notification gets sent to a system-wide server that distributes it to all the tasks that have objects registered for distributed notifications. The latency between posting the notification and the notification’s arrival in another task is unbounded. In fact, when too many notifications are posted and the server’s queue fills up, notifications may be dropped. Distributed notifications are delivered via a task’s run loop. A task must be running a run loop in one of the “common” modes, such as NSDefaultRunLoopMode, to receive a distributed notification. For multithreaded applications running in macOS 10.3 and later, distributed notifications are always delivered to the main thread. For multithreaded applications running in OS X v10.2.8 and earlier, notifications are delivered to the thread that first used the distributed notifications API, which in most cases is the main thread. important: NSDistributedNotificationCenter does not implement a secure communications protocol. When using distributed notifications, your app should treat any data passed in the notification as untrusted. See Security Overview for general guidance on secure coding practices. note: NSDistributedNotificationCenter objects should not be used to send notifications between threads within the same task. Use Distributed Objects Programming Topics or the NSObject method performSelector(onMainThread:with:waitUntilDone:), instead. You can also setup an Port object to receive and distribute messages from other threads.

## Topics

### Getting Distributed Notification Centers

- [default()](foundation/distributednotificationcenter/default().md)
- [forType(_:)](foundation/distributednotificationcenter/fortype(_:).md)

### Managing Observers

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

### Posting Notifications

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

### Suspending and Resuming Notification Delivery

- [suspended](foundation/distributednotificationcenter/suspended.md)

### Constants

- [DistributedNotificationCenter.Options](foundation/distributednotificationcenter/options.md)
- [DistributedNotificationCenter.CenterType](foundation/distributednotificationcenter/centertype.md)
- [DistributedNotificationCenter.SuspensionBehavior](foundation/distributednotificationcenter/suspensionbehavior.md)

### Initializers

- [init(forType:)](foundation/distributednotificationcenter/init(fortype:).md)

## Relationships

### Inherits From

- [NotificationCenter](foundation/notificationcenter.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
