<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSNotification",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSNotification"
  },
  "title" : "NSNotification"
}
-->

# NSNotification

A container for information broadcast through a notification center to all registered observers.

```
class NSNotification
```

## Overview

In Swift, this object bridges to [`Notification`](/documentation/Foundation/Notification); use [`NSNotification`](/documentation/Foundation/NSNotification) when you need reference semantics or other Foundation-specific behavior.

A notification contains a name, an object, and an optional dictionary, and is broadcast to by instances of  [`NotificationCenter`](/documentation/Foundation/NotificationCenter) or [`DistributedNotificationCenter`](/documentation/Foundation/DistributedNotificationCenter). The name is a tag identifying the notification. The object is any object that the poster of the notification wants to send to observers of that notification (typically, the object posting the notification). The dictionary stores other related objects, if any. [`NSNotification`](/documentation/Foundation/NSNotification) objects are immutable.

You don’t usually create your own notifications directly, but instead call the [`NotificationCenter`](/documentation/Foundation/NotificationCenter) methods [`post(name:object:)`](/documentation/Foundation/NotificationCenter/post(name:object:)) and [`post(name:object:userInfo:)`](/documentation/Foundation/NotificationCenter/post(name:object:userInfo:)).

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/Notification`` structure, which bridges to the ``doc://com.apple.foundation/documentation/Foundation/NSNotification`` class. For more information about value types, see <doc://com.apple.documentation/documentation/Swift/working-with-foundation-types>.

### Object Comparison

The objects of a notification are compared using pointer equality for local notifications. Distributed notifications use strings as their objects, and those strings are compared using <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/isEqual(_:)>, because pointer equality doesn’t make sense across process boundaries.

### Creating Subclasses

You can subclass [`NSNotification`](/documentation/Foundation/NSNotification) to contain information in addition to the notification name, object, and dictionary. This extra data must be agreed upon between notifiers and observers.

[`NotificationCenter`](/documentation/Foundation/NotificationCenter) is a class cluster with no instance variables. As such, you must subclass [`NSNotification`](/documentation/Foundation/NSNotification) and override the primitive methods [`name`](/documentation/Foundation/NSNotification/name-swift.property), [`object`](/documentation/Foundation/NSNotification/object), and [`userInfo`](/documentation/Foundation/NSNotification/userInfo). You can choose any designated initializer you like, but be sure that your initializer does not call [`init`](/documentation/Foundation/NSNotification/init) on `super` ([`NSNotification`](/documentation/Foundation/NSNotification) is not meant to be instantiated directly, and its `init` method raises an exception).

## Topics

### Creating Notifications

[`init`](/documentation/Foundation/NSNotification/init)

Initializes an empty notification.

[`init(coder:)`](/documentation/Foundation/NSNotification/init(coder:))

Initializes a notification with the data from an unarchiver.

[`init(name:object:)`](/documentation/Foundation/NSNotification/init(name:object:))

Returns a new notification object with a specified name and object.

[`notificationWithName:object:userInfo:`](/documentation/Foundation/NSNotification/notificationWithName:object:userInfo:)

Returns a notification object with a specified name, object, and user information.

[`init(name:object:userInfo:)`](/documentation/Foundation/NSNotification/init(name:object:userInfo:))

Initializes a notification with a specified name, object, and user information.

[`NSNotification.Name`](/documentation/Foundation/NSNotification/Name-swift.struct)

A structure that defines the name of a notification.

### Getting Notification Information

[`name`](/documentation/Foundation/NSNotification/name-swift.property)

The name of the notification.

[`object`](/documentation/Foundation/NSNotification/object)

The object associated with the notification.

[`userInfo`](/documentation/Foundation/NSNotification/userInfo)

The user information dictionary associated with the notification.

## See Also

  [Notification Programming Topics](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html#//apple_ref/doc/uid/10000043i)



---

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)
