<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTNSNotificationExpectation",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTNSNotificationExpectation"
  },
  "title" : "XCTNSNotificationExpectation"
}
-->

# XCTNSNotificationExpectation

An expectation that is fulfilled when an expected `NSNotification` is received.

```
class XCTNSNotificationExpectation
```

## Topics

### Creating NSNotification Expectations

[`-  initWithName:`](/documentation/XCTest/XCTNSNotificationExpectation/init(name:))

Creates an expectation that is fulfilled when an `NSNotification` is posted from the default notification center by any object.

[`-  initWithName:object:`](/documentation/XCTest/XCTNSNotificationExpectation/init(name:object:))

Creates an expectation that is fulfilled when an `NSNotification` is posted from the default notification center by a specific object.

[`-  initWithName:object:notificationCenter:`](/documentation/XCTest/XCTNSNotificationExpectation/init(name:object:notificationCenter:))

Creates an expectation that is fulfilled when an `NSNotification` is posted from a specific notification center, optionally by a specific object.

### Expectation Properties

[`notificationName`](/documentation/XCTest/XCTNSNotificationExpectation/notificationName)

The name of the notification that the expectation is waiting for.

[`observedObject`](/documentation/XCTest/XCTNSNotificationExpectation/observedObject)

The object by which the notification must be posted, or nil if the notification can be posted by any object.

[`notificationCenter`](/documentation/XCTest/XCTNSNotificationExpectation/notificationCenter)

The notification center from which the notification must be posted.

### Custom Notification Evaluation

[`handler`](/documentation/XCTest/XCTNSNotificationExpectation/handler-swift.property)

An optional handler that performs custom evaluation of matching notifications.

[`Handler`](/documentation/XCTest/XCTNSNotificationExpectation/Handler-swift.typealias)

A custom handler to be called when a matching notification is received.

## Relationships

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

[`XCTestExpectation`](/documentation/XCTest/XCTestExpectation)

---

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)