Latest 0.3.0
Homepage https://github.com/ChaosCoder/Shouter
License MIT
Platforms ios 8.0, osx 10.9, requires ARC
Authors

Shouter
[Shouter]() [Shouter]() Shouter Shouter

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:

protocol SomeNotification {
  func somethingHappened(value: String)
}

class ViewController: UIViewController { /* ... */ }

extension ViewController: SomeNotification {
  func somethingHappened(value: String) {
    self.titleLabel.text = "Something happened: (value)"
  }
}

Have an observer:

let vc = 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'

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.

Latest podspec

{
    "name": "Shouter",
    "version": "0.3.0",
    "summary": "A type safe, thread safe and memory safe alternative for NotificationCenter",
    "homepage": "https://github.com/ChaosCoder/Shouter",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "ChaosCoder": "https://github.com/ChaosCoder"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "source": {
        "git": "https://github.com/ChaosCoder/Shouter.git",
        "tag": "0.3.0"
    },
    "source_files": "Shouter/*.swift",
    "swift_version": "4.2",
    "requires_arc": true
}

Pin It on Pinterest

Share This