Latest 0.3.1
Homepage https://github.com/TakeScoop/Kugel
License MIT
Platforms osx 10.9, ios 8.0, tvos 9.0, requires ARC
Authors

Tests
Platforms
Languages
Cocoapods

A glorious Swift wrapper around NSNotificationCenter.

⚠️ Deprecated ⚠️

This library is deprecated and will not be maintained anymore.

With Swift 3, working with NotificationCenter is more concise so we recommend using NotificationCenter.default directly.

The only feature that Kugel had over using NotificationCenter was to subscribe to multiple events at once using a notification name => selector map, but this can be easily implemented in your own code using the following extension:

extension NotificationCenter {
    func addObserver(_ observer: Any, _ namesAndSelectors: [NSNotification.Name: Selector], object: Any? = nil) {
        for (name, selector) in namesAndSelectors {
            addObserver(observer, selector: selector, name: name, object: object)
        }
    }
    func removeObserver(_ observer: Any, names: [NSNotification.Name], object: Any? = nil) {
        for name in names {
            removeObserver(observer, name: name, object: object)
        }
    }
}

Install

pod 'Kugel'

Usage

Publish

Kugel.publish("NotificationName")
Kugel.publish("NotificationName", object: anObject)
Kugel.publish("NotificationName", userInfo: ["foo": "bar"])
Kugel.publish("NotificationName", object: anObject, userInfo: ["foo": "bar"])
Kugel.publish(NSNotification(name: "NotificationName"))

Subscribe

let token = Kugel.subscribe("NotificationName") { notification in }

Kugel.subscribe(self, name: "NotificationName", selector: "onNotificationReceived:")

Kugel.subscribe(self, name: "NotificationName", selector: "onNotificationReceived:", object: object)

Kugel.subscribe(self, [
    "NotificationName1": "onNotification1Received:",
    "NotificationName2": "onNotification2Received:",
])

Kugel.subscribe(self, [
    "NotificationName1": "onNotification1Received:",
    "NotificationName2": "onNotification2Received:",
], object: object)

Unsubscribe

Kugel.unsubscribe(token)

Kugel.unsubscribe(self, name: "NotificationName")

Kugel.unsubscribe(self, name: "NotificationName", object: object)

Kugel.unsubscribe(self, [
    "NotificationName1",
    "NotificationName2"
])

Kugel.unsubscribe(self, [
    "NotificationName1",
    "NotificationName2"
], object: object)

Kugel.unsubscribe(self)

License

This project is copyrighted under the MIT license. Complete license can be found here: https://github.com/TakeScoop/Kugel/blob/master/LICENSE

Bone icon made by Freepik from http://www.flaticon.com

Latest podspec

{
    "name": "Kugel",
    "version": "0.3.1",
    "summary": "A glorious Swift wrapper around NSNotificationCenter",
    "description": "Easily publish/subscribe/unsubscribe to/from notifications withna convenient Swift syntax for NSNotificationCenter.",
    "homepage": "https://github.com/TakeScoop/Kugel",
    "license": "MIT",
    "authors": {
        "Scoop": "[email protected]"
    },
    "source": {
        "git": "https://github.com/TakeScoop/Kugel.git",
        "tag": "0.3.1"
    },
    "source_files": "Kugel/Kugel.swift",
    "requires_arc": true,
    "platforms": {
        "osx": "10.9",
        "ios": "8.0",
        "tvos": "9.0"
    },
    "deprecated": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This