Platformsios 8.0, osx 10.9, requires ARC


[![](]() [![](]()

A Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety.

– Type Safe

No more `userInfo` dictionary and Downcasting, just deliver the concrete type value to the observer.

– Thread Safe

You can `register`, `notify`, `unregister` in any thread without crash and data corruption.

– Memory Safety

`SwiftNotificationCenter` store the observer as a zeroing-weak reference. No crash and no need to `unregister` manually.

It’s simple, safe, lightweight and easy to use for `one-to-many` communication.

## Usage

Define protocol and observer:

protocol Update {
func updateTitle(title: String)

extension ViewController: Update {
func updateTitle(title: String) {
self.titleLabel.text = title
let vc = ViewController()


Broadcaster.register(Update.self, observer: vc)


Broadcaster.notify(Update.self) {
$0.updateTitle(“new title”)


Broadcaster.unregister(Update.self, observer: self)

Compare with `NSNotificationCenter` :

For example, handle `UIKeyboardWillShowNotification`

@objc func handleKeyboardNotification(notification: NSNotification) {
guard == NSNotification.Name.UIKeyboardWillShow
else { return }

guard let beginFrame = (notification
.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
else { return }

guard let endFrame = (notification
.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
else { return }
// use beginFrame, endFrame

`SwiftNotificationCenter` way:

If you want to observe the system built in notifications like this.
You can declare a protocol and the relevant method, and use a singleton as a mediator to observe system’s notification, then notify our observers.
Please check the refactor example in SwiftNotificationCenterExample Project.
func UIKeyboardWillShow(beginFrame: CGRect, endFrame: CGRect) {

## Installation


pod ‘SwiftNotificationCenter’


github “100mango/SwiftNotificationCenter”


Just copy source files in the SwiftNotificationCenter folder into your project.

## License

`SwiftNotificationCenter` is under the MIT license.

Latest podspec

    "name": "SwiftNotificationCenter",
    "version": "1.0.3",
    "summary": "A Type Safe, Thread Safe, ARC Safe Protocol Oriented NotificationCenter",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    "authors": {
        "100mango": ""
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    "source": {
        "git": "",
        "tag": "1.0.3"
    "source_files": "SwiftNotificationCenter/*.swift",
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This