Contents

addObserver(of:for:using:)

Adds an observer to a center for messages delivered on the main actor with a given subject and message type.

Declaration

func addObserver<Message>(of subject: Message.Subject? = nil, for messageType: Message.Type, using observer: @escaping @MainActor (Message) -> Void) -> NotificationCenter.ObservationToken where Message : NotificationCenter.MainActorMessage, Message.Subject : AnyObject

Parameters

  • subject:

    The subject to be observed. Specify a metatype to observe all values for a given type.

  • messageType:

    The message type to be observed.

  • observer:

    A closure to execute when receving a message.

Return Value

A token representing the observation registration with the given notification center.

See Also

Observing concurrency-safe notifications