addObserver(of:for:using:)
Adds an observer to a center for messages delivered asynchronously with a given subject and identifier.
Declaration
func addObserver<Identifier, Message>(of subject: Message.Subject, for identifier: Identifier, using observer: @escaping @Sendable (Message) async -> Void) -> NotificationCenter.ObservationToken where Identifier : NotificationCenter.MessageIdentifier, Message : NotificationCenter.AsyncMessage, Message == Identifier.MessageType, Message.Subject : AnyObjectParameters
- subject:
The subject to observe. Specify a 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.