EventSource
public struct EventSource<T>
Exposes an event source point that can be subscribed into in order to receive future events issued by the an event publisher associated with this event source.
-
Adds a new event listener to this event source.
The
weakOwner
object is held weakly, and the event listener is automatically removed when theowner
turnsnil
.Declaration
Swift
@discardableResult public func addListener(weakOwner: AnyObject, _ listener: @escaping (T) -> Void) -> EventListenerKey
-
Adds a new event listener to this event source.
The
weakOwner
object is held weakly, and the event listener is automatically removed when theweakOwner
turnsnil
.Declaration
Swift
@discardableResult public func addListener(weakOwner: AnyObject, _ listener: @escaping () -> Void) -> EventListenerKey where T == ()
-
Convenience for:
addListener(weakOwner: owner) { [weak owner] value in guard let owner else { return } ... }
Declaration
Swift
@discardableResult public func addWeakListener<U>(_ weakOwner: U, _ listener: @escaping (U, T) -> Void) -> EventListenerKey where U : AnyObject
-
Requesta that an event listener associated with a given key be unsubscribed and no longer receive any events.
Declaration
Swift
public func removeListener(forKey key: EventListenerKey)
-
Removes all event subscriptions associated with a given owner object, by verifying the original
weakOwner
argument that was passed toaddListener(weakOwner:_:)
. Matching is done by object identity, i.e. via===
.Declaration
Swift
public func removeAll(fromOwner owner: AnyObject)