Latest 1.0
Homepage https://github.com/mishimay/EventKit
License MIT
Platforms ios 8.0, requires ARC
Authors

EventHub

Type-safe and handy observation system in Swift.

Quick Example

struct MessageEvent: EventType {
    let message: String
}

EventHub.addObserver(self) { (event: MessageEvent) in
    print(event.message) // -> 😜
}
EventHub.post(MessageEvent(message: "😜"))

Usage

  1. Define events which adopt EventType protocol
    The event can be a class, structure, or enumeration.

    enum LoginEvent: EventType {
      case Success(id: String)
      case Failure(error: ErrorType)
    }
  2. Add observers and blocks
    Call addObserver(observer:thread:block:).

    • observer: An observer object. If the observer object is destroyed, the observation will be removed automatically and the block will never be called.
    • thread: Optional (default is nil). It determines that which thread executes the block. If it’s nil, the block is run synchronously on the posting thread.
    • block: A callback closure. The block receives the defined event.
    EventHub.addObserver(self, thread: .Main) { (event: LoginEvent) in
      switch event {
      case .Success(let id):
          print(id)
      case .Failure(let error):
          print(error)
      }
    }
  3. Post events
    EventHub.post(LoginEvent.Success(id: id))

Requirements

Swift 2.1

Installation

EventHub is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "EventHub"

Author

Yuki Mishima, [email protected]

License

EventHub is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "EventKit",
    "version": "1.0",
    "summary": "Type-safe and handy observation system in Swift.",
    "homepage": "https://github.com/mishimay/EventKit",
    "license": "MIT",
    "authors": {
        "Yuki Mishima": "[email protected]"
    },
    "source": {
        "git": "https://github.com/mishimay/EventKit.git",
        "tag": "1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "EventKit": [
            "Pod/Assets/*.png"
        ]
    },
    "deprecated": true
}

Pin It on Pinterest

Share This