A glorious Swift wrapper around NSNotificationCenter

Overview

Kugel

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

You might also like...
A custom wrapper over AFNetworking library that we use inside RC extensively

AFNetworkingHelper A very simple wrapper over the most amazing networking library for objective C, AFNetworking. We extensively use it inside RC and i

Github API V3 Swifty Wrapper

GithubPilot - Github API V3 Swifty Wrapper This is a Swift Github API Wrapper, it could make your life a little easier if you want to make an App with

AsyncWebSocketClient - A package that contains a client behaving as a wrapper for the URLSessionWebSocketTask

(WORK IN PROGRESS) AsyncWebSocketClient This is a package that contains a client

Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)

Perfect: Server-Side Swift 简体中文 Perfect: Server-Side Swift Perfect is a complete and powerful toolbox, framework, and application server for Linux, iO

Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-5.1

Swift Express is a simple, yet unopinionated web application server written in Swift
Swift Express is a simple, yet unopinionated web application server written in Swift

Documentation h5 align="right"a href="http://demo.swiftexpress.io/"Live 🐧 server running Demo img src="https://cdn0.iconfinder.com/data/icons/

Swift backend / server framework (Pure Swift, Supports Linux)

NetworkObjects NetworkObjects is a #PureSwift backend. This framework compiles for OS X, iOS and Linux and serves as the foundation for building power

Swift-multipart-formdata - MultipartFormData: Build multipart/form-data type-safe in Swift

MultipartFormData Build multipart/form-data type-safe in Swift. A result builder

Quickstart-ios-swift-grpc - Quickstart for integrating Approov with iOS apps in Swift that make API requests you wish to protect using GRPC
Comments
  • Changed function parameter types to match the ones in NSNotificationCenter

    Changed function parameter types to match the ones in NSNotificationCenter

    Changed function parameter types to match the ones in NSNotificationCenter so passing the sender is optional in case when you want to attach userInfo to the notification object.

    e.g. Kugel.publish("sessionChanged", object: nil, userInfo: ["key" : "val"])

    opened by nmarkovic04 1
  • Fixed Swift 3.0 errors

    Fixed Swift 3.0 errors

    Kugel.subscribe("test") returns an error in Swift 3.0: "Cannot convert value of type 'String' to expected argument type 'NSNotification.Name' Kugel.publish("test") returns an error: "Cannot convert value of type 'String' to expected argument type 'Notification'"

    The way Notifications work in the new version of Swift has changed. This pull requests solves those issues.

    opened by csr 0
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
Owner
Scoop
Scoop
A testable RxSwift wrapper around MultipeerConnectivity

A testable RxSwift wrapper around MultipeerConnectivity

RxSwift Community 69 Jul 5, 2022
A Combine-style wrapper around Network's NWConnection with a UDP protocol

A Combine-style wrapper around Network's NWConnection with a UDP protocol

Emlyn Bolton 3 Sep 26, 2022
Lightweight lib around NSURLSession to ease HTTP calls

AeroGear iOS HTTP Thin layer to take care of your http requests working with NSURLSession. Project Info License: Apache License, Version 2.0 Build: Co

AeroGear 44 Sep 27, 2022
Http Request wrapper written in Swift

Net Net is a HttpRequest wrapper written in Swift Features GET, POST, PUT, DELETE method Powerful request params: nested params, number, string, dic,

Le Van Nghia 304 Jun 29, 2022
A WIP Swift wrapper for Discord's Bot API.

Quickcord Quickcord is a WIP Swift wrapper for Discord's Bot API. Features (As of right now) Connecting the the gateway and identifying. Literally eve

Ben Sova 4 Aug 7, 2021
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support

Networking was born out of the necessity of having a simple networking library that doesn't have crazy programming abstractions or uses the latest rea

Nes 1.3k Dec 17, 2022
A modern Swift wrapper for Instagram Private API.

Swiftagram is a wrapper for Instagram Private API, written entirely in (modern) Swift. Instagram's official APIs, both the Instagram Basic Display API

Stefano Bertagno 217 Dec 27, 2022
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

Wilson Ding 197 Nov 2, 2022
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

Ronan Rodrigo Nunes 89 Dec 26, 2022
Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone

ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier

Ben Copsey 5.8k Dec 14, 2022