subscribe(to:componentType:_:)
Subscribes to an event type, optionally limited to a specific component type for component events.
Declaration
func subscribe<E>(to event: E.Type, componentType: (any Component.Type)? = nil, _ handler: @escaping (E) -> Void) -> EventSubscription where E : EventParameters
- event:
The event type to subscribe to. For example, Update or Didactivate.
- componentType:
An optional component type to filter events to if the event is of the type Componentevents. Set to
nilto listen for all events of the event type within the view content. - handler:
A closure that runs when the
eventoccurs.
Return Value
An object that represents the subscription to this event stream.
Discussion
Events you can subscribe to including scene updates, SceneEvents.Update, or when an animation ends, AnimationEvents.PlaybackCompleted.