SubscriptionManager

public class SubscriptionManager<Event>

Manage subscriptions to event notifications. Events can be anything but are usually defined as an enum.

  • The type of function / closure that is used to subscribe to a subscription manager

    Declaration

    Swift

    public typealias NotifierProc = (Event) -> Void
  • The type of function / closure that is used to unsubscribe to a subscription manager

    Declaration

    Swift

    public typealias UnsubscribeProc = () -> Void
  • Construct a new subscription manager

    Declaration

    Swift

    public init(_ cacheEvent: Bool = false)

    Parameters

    cacheEvent

    when true, hold onto the last event and use it when there are new subscriptions

  • Establish a connection between the SubscriptionManager and the notifier such that any future Events will be sent to the notifier.

    Declaration

    Swift

    @discardableResult
    public func subscribe<O: AnyObject>(_ subscriber: O, notifier: @escaping NotifierProc)
      -> SubscriberToken

    Parameters

    subscriber

    the object that is subscribing – if it dies, then the subscription is automatically removed.

    notifier

    the closure to invoke for each new Event

    Return Value

    a token that knows how to unsubscribe

  • Notify all subscribers of a new event.

    Declaration

    Swift

    public func notify(_ event: Event)

    Parameters

    event

    the event that just took place