<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NotificationCenter/addObserver(of:for:using:)-t1wr",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So20NSNotificationCenterC10FoundationE11addObserver2of3for5usingAbCE16ObservationTokenV7SubjectQy_m_xyq_YaYbctAbCE17MessageIdentifierRzAbCE05AsyncL0R_0L4TypeQzRs_r0_lF"
  },
  "title" : "addObserver(of:for:using:)"
}
-->

# addObserver(of:for:using:)

Adds an observer to a center for messages delivered asynchronously with a given subject and message type.

```
func addObserver<Identifier, Message>(of subject: Message.Subject.Type, for identifier: Identifier, using observer: @escaping @Sendable (Message) async -> Void) -> NotificationCenter.ObservationToken where Identifier : NotificationCenter.MessageIdentifier, Message : NotificationCenter.AsyncMessage, Message == Identifier.MessageType
```

## Parameters

`subject`

The metatype to observe all values for a given type.

`identifier`

An identifier representing a specific message type.

`observer`

A closure to execute when receving a message.

## Return Value

A token representing the observation registration with the given notification center. Retain this token for as long as you need to receive messages.

---

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)