All Projects → mergesort → Typednotifications

mergesort / Typednotifications

Licence: mit
A mechanism for sending typed notifications with payloads across your iOS app.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Typednotifications

Webmention Client Ruby
A Ruby gem for sending Webmention notifications.
Stars: ✭ 60 (-14.29%)
Mutual labels:  notifications
Push.js
The world's most versatile desktop notifications framework 🌎
Stars: ✭ 8,536 (+12094.29%)
Mutual labels:  notifications
Reapop
📮 A simple and customizable React notifications system
Stars: ✭ 1,155 (+1550%)
Mutual labels:  notifications
Peony Twitter
An asynchronous Twitter API client for Python 3.5+
Stars: ✭ 62 (-11.43%)
Mutual labels:  asynchronous
Php Ion
Asynchronous PHP
Stars: ✭ 65 (-7.14%)
Mutual labels:  asynchronous
Cats Effect
The pure asynchronous runtime for Scala
Stars: ✭ 1,147 (+1538.57%)
Mutual labels:  asynchronous
Collie
An asynchronous event-driven network framework( port netty ) written in D.
Stars: ✭ 60 (-14.29%)
Mutual labels:  asynchronous
Checknewappversionavailable
It makes a request to Play Store to check if there is a new version of your published app
Stars: ✭ 69 (-1.43%)
Mutual labels:  notifications
Notificationpusher
Standalone PHP library for easy devices notifications push.
Stars: ✭ 1,143 (+1532.86%)
Mutual labels:  notifications
Notify Py
💬 | A simple Python Module for sending cross-platform desktop notifications on Windows, macOS and Linux
Stars: ✭ 68 (-2.86%)
Mutual labels:  notifications
Klaxon
Mac OS notifications from Python
Stars: ✭ 63 (-10%)
Mutual labels:  notifications
Github Releases Notify Bot
Allows you to receive notifications of new releases of software on GitHub in Telegram
Stars: ✭ 65 (-7.14%)
Mutual labels:  notifications
Calendarnotification
Android app extending calendar notifications with snooze button and notifications persistence
Stars: ✭ 67 (-4.29%)
Mutual labels:  notifications
E Commerce App React Native
E-commerce App UI. React native, Expo managed flow, React navigation v5, Notification.
Stars: ✭ 61 (-12.86%)
Mutual labels:  notifications
Kju
Kju — Improved waiting time for the adidas.com splash page ❯❯❯_
Stars: ✭ 68 (-2.86%)
Mutual labels:  notifications
Teller Cli
🏦 Banking for your command line.
Stars: ✭ 60 (-14.29%)
Mutual labels:  notifications
Esa Restlight
ESA Restlight is a lightweight and rest-oriented web framework.
Stars: ✭ 67 (-4.29%)
Mutual labels:  asynchronous
Countly Sdk Cordova
Countly Product Analytics SDK for Cordova, Icenium and Phonegap
Stars: ✭ 69 (-1.43%)
Mutual labels:  notifications
Rocket.jl
Functional reactive programming extensions library for Julia
Stars: ✭ 69 (-1.43%)
Mutual labels:  asynchronous
Notifier
Notifications library made with VanillaJS.
Stars: ✭ 67 (-4.29%)
Mutual labels:  notifications

TypedNotifications

A wrapper around NotificationCenter for sending typed notifications with payloads across your iOS app.

BuddyBuild Pod Version Swift Version License MIT Plaform

Asynchronous behavior is hard. Let's make it a little easier so we can turn that frown (🙁) upside down (🙃).


Using TypedNotifications is easy. You can drop it into your app and replace all of your un-typed Notifications in minutes.


Registering for Notifications

You can register notifications for either payload containing notifications, or payload-free notifications.

func register<T: TypedNotification>(type: T.Type, observer: Any, object: Any? = nil, selector: Selector)
func register<T: TypedPayloadNotification>(type: T.Type, observer: Any, object: Any? = nil, selector: Selector)

Sending Notifications

You can send notifications for either payload containing notifications, or payload-free notifications.

func post<T: TypedNotification>(typedNotification: T, object: Any? = nil)
func post<T: TypedPayloadNotification>(typedNotification: T, object: Any? = nil)

Extracting values from Notifications

Only payload containing notifications can have their payload extracted, because, duh.

func getPayload<T: TypedPayloadNotification>(notificationType: T.Type) -> T.Payload?

Now that might look a little scary at first with all those Ts, but let's break it down with some examples and show you how easy this is.

Examples

Create some values you'd like to send through your app.

enum Job {
    
    case softwareDeveloper
    case designer
    case conArtist

}

struct Person {

    let name: String
    let job: Job

}

Create the notification to send your value

If you have no payload and just want to send a message, use a TypedNotification like so.

struct SomeEventNotification: TypedNotification {}

For our example, let's use a TypedPayloadNotification with a payload though.

struct TypedPersonNotification: TypedPayloadNotification {

    let payload: Person

}

Register the notification

NotificationCenter.default.register(type: TypedPersonNotification.self, observer: self, selector: #selector(personNotificationWasReceived))

Send the notification

let amanda = Person(name: "Amanda", job: .softwareDeveloper)
let amandaNotification = TypedPersonNotification(payload: amanda)
NotificationCenter.default.post(typedNotification: amandaNotification)

And handle the notification

@objc func personNotificationWasReceived(notification: Notification) {
    guard let person = notification.getPayload(notificationType: TypedPersonNotification.self) else {
        os_log("Could not properly retrieve payload from TypedPersonNotification")
        return
    }
    
    let nameText = "Name: \(person.name)"
    let jobText = "Job: \(person.job.title)"

    print("Got our Person payload!\n\(nameText)\n\(jobText)")
}

And that's it! You've sent a typed notification throughout your app.

If you want to play on expert mode, I recommend using generics and passing notifications through your app that way.

struct GenericTypedPayloadNotification<T>: TypedPayloadNotification {

    let payload: T

}

Requirements

  • iOS 8.0+
  • Xcode 7.3+

Installation

SPM will be the default supported installation method from version 1.4.0 and higher, so please integrate by using SPM.

If you're still using CocoaPods for version 1.4.0 or below you can install TypedNotifications by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'TypedNotifications'

Or install it manually by downloading TypedNotifications.swift and dropping it in your project.

About me

Hi, I'm Joe everywhere on the web, but especially on Twitter.

License

See the license for more information about how you can use TypedNotifications.

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].