Envoy 1.0.0

Envoy 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Pawel Dudek.



Envoy 1.0.0

  • By
  • Pawel Dudek and Paweł Kozielecki

Envoy

Envoy is a protocol-oriented thread-safe replacement of NSNotificationCenter. At AirHelp we believe that in most cases using NSNotificationCenter is an anti-pattern (many words have been said on this subject).

Moreover NSNotificationCenter API feels antique in the Swift world, with string-based event registration, selectors and requirement of @objc methods.

So we decided to build a replacement that will give us a solution similar to NSNotificationCenter but without the way-too-loose coupling and with a much nicer Swift API.

Thus Envoy was born.

Usage

In order to register for notifications for given object and given protocol you need to call:

Envoy.register(AuthenticationObserver.self, observer: observer, object: poster)

To post notification you need to call

Envoy.notify(AuthenticationObserver.self, object: poster) { observer in
    observer.didAuthenticate()
}

And that’s it! Envoy takes care of routing to appropriate objects based on passed in protocol and object you wish to observe. Moreover it automatically handles weak references, there’s no need to unregister upon deinit.

Installation

Swift Package Manager

Envoy is also available via Swift Package Manager. You can add it by defining a dependency:

.Package(url: "https://github.com/airhelp/envoy.git", majorVersion: 1),

Authors

Envoy is an AirHelp open source project, designed and implemented by

License

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