Skip to content

Repository files navigation

Shouter is a simple, safe, lightweight way for one-to-many communication. It is a type, memory and thread safe alternative for NotificationCenter.

  • Type Safe: No more userInfo: [String: Any] dictionary guarded casting.
  • Thread Safe: You can register, notify, unregister in any thread without crash and data corruption.
  • Memory Safe: Shouter stores observers as a zeroing-weak reference by using NSHashTable. No crash and no need to unregister manually before deallocating.

Usage

Define a protocol, that your observer implements:

protocolSomeNotification{func somethingHappened(value:String)}classViewController:UIViewController{ /* ... */ }extensionViewController:SomeNotification{func somethingHappened(value:String){self.titleLabel.text ="Something happened: \(value)"}}

Have an observer:

letvc=ViewController()

Register the observer for the notification:

Shouter.default.register(SomeNotification.self, observer: vc)

Notify all observers:

Shouter.default.notify(SomeNotification.self){
$0.somethingHappened(value:"Hello World")}

Unregister, when the observer is not interested in the notification anymore:

Shouter.default.unregister(SomeNotification.self, observer: vc)

Installation

CocoaPods:

pod 'Shouter'

Swift Package Manager:

.package(url:"https://github.com/ChaosCoder/Shouter.git", from:"0.5.0")

Acknowledgments

Shouter was inspired and partially based on the library 100mango/SwiftNotificationCenter.
The logo is based on the "Broadcast" icon by Amy Chiang from the Noun Project.

About

Library for One-to-Many communication in Swift Apps

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages