This is type-safe publish/subscribe implementation, where you use custom enums as events.
Inherit Event protocol in your events enum.
enum User: Event {
case Followed
case Unfollowed
}
You can subscribe to closure.
Eventer.subscribe(Events.User.Followed) {
}
And you can subscribe to function or method.
Eventer.subscribe(Events.User.Unfollowed, action: self.onNeedToReload)
Closure or function can be with or without info argument.
Eventer.subscribe(Events.User.Followed) { (info) in
}
You can use subscribe to several events.
Eventer.subscribe([Events.User.Followed, Events.User.Unfollowed], action: self.onNeedToReload)
You can publish events defined in custom enums.
Eventer.publish(Events.User.Followed)
And you can publish events with additional info.
Eventer.publish(Events.Route.Added, info: "Super user")
You can asynchronously publish events in background or main thread.
Eventer.publish(Events.User.Followed, to: .Background)
Eventer.publish(Events.User.Followed, to: .Main)