<!--
{
  "availability" : [

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

# init(name:object:)

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

```
convenience init(name notificationName: NSNotification.Name, object: Any?)
```

## Parameters

`notificationName`

The notification name to watch for.

`object`

The object by which the notification must be posted.

## Discussion

---

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)