Skip to content

ProtocolFoundationEssentials

NotificationCenter.MessageIdentifier

iOS 26.0+ iPadOS 26.0+ Mac Catalyst 26.0+ macOS 26.0+ tvOS 26.0+ visionOS 26.0+ watchOS 26.0+
An optional identifier to associate a given message with a given type.
protocol MessageIdentifier

Overview

Implement a MessageIdentifier to provide a typed, ergonomic experience at the call point, as described in SE-0299.

For example, given ExampleMessage with a Subject called ExampleSubject:

extension NotificationCenter.MessageIdentifier where Self == NotificationCenter.BaseMessageIdentifier<ExampleMessage> {
    static var eventDidOccur: Self { .init() }
}

This simplifies the call point for clients, as seen here:

let token = center.addObserver(of: exampleSubject, for: .eventDidOccur) { ... }

Topics

Associated Types

Relationships

Conforming Types