HIPEventSource

open class HIPEventSource: NSObject

Collects callbacks and allows them to be fired. Each callback is associated with an object. If that object is ever deallocated, the callback will no longer be called.

  • You may assign this to a block which is called whenever a subscriber is added to this event source.

    Declaration

    Swift

    open var onSubscriberAdded: (AnyObject, ()->()) -> () = { _ in }
  • Add a callback associated with object.

    Declaration

    Swift

    open func subscribe(withObject object: AnyObject, callback: @escaping () -> ()) -> () -> ()

    Parameters

    object

    When this object is deallocated, the callback will also be deallocated.

    callback

    A block or function to be called when fireEvent is called. (For HIPEventSourceWithValue variants, these callbacks are called whenever value changes.

    Return Value

    A function which you may call to remove the callback so it will no longer be called or referenced by this HIPEventSource.

  • Add a callback associated with object, to be called at most once.

    Declaration

    Swift

    open func subscribeOnce(withObject object: AnyObject, callback: @escaping () -> ()) -> () -> ()

    Parameters

    object

    If this object is deallocated before fireEvent is called, the callback will never be called.

    callback

    A block or function to be called when fireEvent is called, and then discarded.

    Return Value

    A function which you may call to remove the callback so it will no longer be called or referenced by this HIPEventSource.

  • Remove all subscribers

    Declaration

    Swift

    open func removeAllSubscribers()
  • Call all callbacks whose objects have not yet been deallocated

    Declaration

    Swift

    @objc open func fireEvent()