All Projects â†’ SwiftKitz â†’ Notificationz

SwiftKitz / Notificationz

Licence: mit
📡 Helping you own NotificationCenter in Swift!

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Notificationz

Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (+113.51%)
Mutual labels:  watchos, cocoapods, carthage
Datez
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
Stars: ✭ 254 (+243.24%)
Mutual labels:  watchos, cocoapods, carthage
Cocoalumberjack
A fast & simple, yet powerful & flexible logging framework for Mac and iOS
Stars: ✭ 12,584 (+16905.41%)
Mutual labels:  watchos, cocoapods, carthage
Contentful.swift
A delightful Swift interface to Contentful's content delivery API.
Stars: ✭ 132 (+78.38%)
Mutual labels:  watchos, cocoapods, carthage
Swiftframeworktemplate
A template for new Swift iOS / macOS / tvOS / watchOS Framework project ready with travis-ci, cocoapods, Carthage, SwiftPM and a Readme file
Stars: ✭ 527 (+612.16%)
Mutual labels:  watchos, cocoapods, carthage
Ducttape
📦 KeyPath dynamicMemberLookup based syntax sugar for Swift.
Stars: ✭ 138 (+86.49%)
Mutual labels:  watchos, cocoapods, carthage
Iso8601
ISO8601 date parser and writer
Stars: ✭ 213 (+187.84%)
Mutual labels:  watchos, cocoapods, carthage
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+14367.57%)
Mutual labels:  watchos, cocoapods, carthage
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+4913.51%)
Mutual labels:  watchos, cocoapods, carthage
Functionkit
A framework for functional types and operations designed to fit naturally into Swift.
Stars: ✭ 302 (+308.11%)
Mutual labels:  watchos, cocoapods, carthage
Coregpx
A library for parsing and creation of GPX location files. Purely Swift.
Stars: ✭ 132 (+78.38%)
Mutual labels:  watchos, cocoapods, carthage
Guitar
A Cross-Platform String and Regular Expression Library written in Swift.
Stars: ✭ 641 (+766.22%)
Mutual labels:  watchos, cocoapods, carthage
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (+60.81%)
Mutual labels:  watchos, cocoapods, carthage
Color
Color utilities for macOS, iOS, tvOS, and watchOS
Stars: ✭ 145 (+95.95%)
Mutual labels:  watchos, cocoapods, carthage
Randomkit
Random data generation in Swift
Stars: ✭ 1,458 (+1870.27%)
Mutual labels:  watchos, cocoapods, carthage
L10n Swift
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
Stars: ✭ 177 (+139.19%)
Mutual labels:  watchos, cocoapods, carthage
Swiftyattributes
A Swifty API for attributed strings
Stars: ✭ 1,303 (+1660.81%)
Mutual labels:  watchos, cocoapods, carthage
Sdwebimagewebpcoder
A WebP coder plugin for SDWebImage, use libwebp
Stars: ✭ 101 (+36.49%)
Mutual labels:  watchos, cocoapods, carthage
Web3.swift
A pure swift Ethereum Web3 library
Stars: ✭ 295 (+298.65%)
Mutual labels:  watchos, cocoapods, carthage
Sdwebimage
Asynchronous image downloader with cache support as a UIImageView category
Stars: ✭ 23,928 (+32235.14%)
Mutual labels:  watchos, cocoapods, carthage

Notificationz 📡

Helping you own NotificationCenter

Version Version Swift Platforms Carthage

Highlights

  • Keep Your Naming Conventions:
    This library gives you convenient access to NotificationCenter, but it's up to you to set it up the way you like!

  • Nothing to Hide:
    Not trying to hide NotificationCenter functionality. Just an attempt to provide a more convenient API

  • Full and Simple Testing:
    Testing this library was simple, since it only forwards calls to NotificationCenter for the most part. Mocking that object allowed tests to reach 100% coverage.

Features

You can try them in the playground shipped with the framework!

Use your own naming convention to wrap NotificationCenter

let nsCenter = NotificationCenter.default
let 📡 = NotificationCenterAdapter(notificationCenter: nsCenter)
📡.post(.💃)

// my personal preference, define this in Globals.swift
let NC = NotificationCenterAdapter(notificationCenter: nsCenter)
// Now, you can use `NC` throughout the app

Four simple keywords to remember

let obj = Object()
NC.add(obj, selector: #selector(Object.call))   // normal add observer
NC.observe { notification in }                  // observe using blocks
NC.post(.tenhut)                                // post a notification
NC.remove(obj)                                  // remove from nsCenter

Transparent and convenient API

let keys = ["observe", "many", "keys"].map { Notification.Name($0) }
NC.observe(keys) { _ in }       // observe on the same thread
NC.observeUI(keys) { _ in }     // delivered to the main thread

NC.post(.test)
NC.post(.test, userInfo: ["info":5])
NC.post(Notification(name: .test, object: nil))

RAII-based observers

class Dummy {

    // declare the observer as optional
    var broadcastObserver: Observer?

    init() {
        // assign it anywhere you like
        broadcastObserver = NC.observe { [unowned self] _ in
            self.doSomething()
        }.execute() // this is a neat bonus feature
    }

    func doSomething() {
        // exectued twice, since we call "execute" manually
        print("it works!")
    }
}

var dummy: Dummy? = Dummy()
NC.post(.test)  // calls doSomething
dummy = nil     // clean up is automatic
NC.post(.test)  // doesn't crash!

Getting Started

Carthage

Carthage is fully supported. Simply add the following line to your Cartfile:

github "SwiftKitz/Notificationz"

Cocoapods

Cocoapods is fully supported. Simply add the following line to your Podfile:

pod 'Notificationz'

Submodule

For manual installation, you can grab the source directly or through git submodules, then simply:

  • Drop the Notificationz.xcodeproj file as a subproject (make sure Copy resources is not enabled)
  • Navigate to your root project settings. Under "Embedded Binaries", click the "+" button and select the Notificationz.framework

Motivation

After migrating to Swift, the NotificationCenter APIs really stood out in the code. Writing so much boiler plate all over the place just to register, handle, and cleanup notifications. Coming from C++, RAII seemed a pretty invaluable pattern to be applied here.

With this framework, one can easily declare all their observers as properties:

class Sample {
    private var keyboardObserver: Observer?
    private var reachabilityObserver: Observer?
}

Other programmers should be pleased with this consistency! Moreover, there is no need to worry handling notifications in some other function somewhere nor do cleanup in deinit. It just works:

keyboardObserver = NC.observeUI(UIKeyboardWillShowNotification) { [unowned self] _ in
    // you can write your handler code here, maybe call another function
}

// you can force cleanup by setting the property to nil, but don't have to
keyboardObserver = nil

Author

Maz (@Mazyod)

License

Notificationz is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].