EventSource

public protocol EventSource

This protocol defines 3 required methods for objects to post and listen for notifications, as well as cancel.

  • Posts a new notification originating from the receiver.

    Declaration

    Swift

    func post(event: String)

    Parameters

    event

    The name of the event to post.

  • Register an action to run when an event is triggered. Returns an observer handle you can use to cancel the action.

    Declaration

    Swift

    func on(event notificationName: String, run: Void -> Void) -> AnyObject

    Parameters

    notificationName

    The notification name to listen for

    executionBlock

    A block of code to run when the receiver hears the specified notification name

  • Register an action to run when an event is triggered by the specified sender. Returns an observer handle you can use to cancel the action.

    Declaration

    Swift

    func on(event notificationName: String, from sender: AnyObject?, run executionBlock: Void -> Void) -> AnyObject

    Parameters

    notificationName

    The notification name to listen for

    sender

    The object from which to listen for the notification

    executionBlock

    A block of code to run when the receiver hears the specified notification name

  • Cancel a previously registered action from an observer handle.

    Declaration

    Swift

    func cancel(observer: AnyObject)