Latest 0.1.0
Homepage https://github.com/dannys42/NotificationUserInfoModel
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Description

NotificationUserInfoModel is a simple set of convenience protocols to make passing data via NotificationCenter more Swift-like.

There are plenty of other NotificationCenter wrappers out there. NotificationUserInfoModel is not intended to compete with them. Rather, if you plan on using NotificationCenter API’s as-is, then this simply helps reduce some boiler-plate code that may be error-prone.

Example

By declaring your NotificaitonUserInfoModel and creating the approprite serializer and deserializer methods, you can easily interface with NotificationCenter:

Declare Model

struct MyNoteModel {
    // add data fields here
    public var exampleString: String
}

Observer

@objc public func notificationObserver(_ note: Notification) {
    guard let myModel = MyNoteModel(note) else { return }

    /* use myModel  */
}

Emitter

let model = MyNoteModel(exampleString: "Example")
NotificationCenter.default.post(name: .ExampleNotification, object: nil, userInfo: model)

For a complete a more complete example, please see the included sample project.

Example Project

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Tested on Xcode 9.2, Swift 4, iOS 10.

Installation

NotificationUserInfoModel is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'NotificationUserInfoModel'

Author

Danny Sung [email protected]

License

NotificationUserInfoModel is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "NotificationUserInfoModel",
    "version": "0.1.0",
    "summary": "A simple (de)serialing protocol to pass data with NotificationCenter.",
    "description": "This pod provides a simple protocol to make it easier to work with NotificationCenter in Swift.",
    "homepage": "https://github.com/dannys42/NotificationUserInfoModel",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "[email protected]": "[email protected]"
    },
    "source": {
        "git": "https://github.com/dannys42/NotificationUserInfoModel.git",
        "tag": "release/0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.0",
    "source_files": "Classes/**/*"
}

Pin It on Pinterest

Share This