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.
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.
Envoy is available through CocoaPods. To install it, simply add the following line to your Podfile against your test target:
pod "Envoy"
You can also use Carthage for installing Envoy. Simply add it to your Cartfile:
github "Airhelp/Envoy"
and then link it with your test target.
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),
Envoy is an AirHelp open source project, designed and implemented by
- Pawel Dudek, @eldudi, [email protected]
- Pawel Kozielecki, @pawelkozielecki, [email protected]
Envoy is available under the MIT license. See the LICENSE file for more info.