Latest 1.1.0
Homepage https://github.com/sobri909/SwiftNotes
License MIT
Platforms ios 10.0
Authors

A super simple wrapper around NotificationCenter.

Setup

pod 'SwiftNotes'

Or just drop SwiftNotes.swift into your project.

UIKit Notification Examples

UIKeyboard Notifications

when(.UIKeyboardDidShow) { note in
    // do stuff 
}

UIApplication Notifications

when(.UIApplicationDidBecomeActive) { _ in
    // do stuff
}

Custom Notifications

Define A Custom Notification

// define the custom event name
extension NSNotification.Name {
    static let somethingHappened = Notification.Name("somethingHappened")
}

Trigger Your Custom Notification

// send your custom event
trigger(.somethingHappened)

Respond To Your Custom Notification

when(.somethingHappened) { _ in
    // do stuff
}

Extra Parameters

Trigger An Event And Include UserInfo

trigger(.somethingHappened, userInfo: ["goodTimes": true])

Trigger An Event On A Specific Sender

trigger(.updatedFromRemote, on: self)

Observe An Event On A Specific Sender

when(model, does: .updatedFromRemote) { _ in
    // do stuff
}

Respond On A Specific Queue

// make sure the closure is run on the main queue
when(.somethingHappened, doOn: OperationQueue.main) _ in 
    // do stuff
}

Latest podspec

{
    "name": "SwiftNotes",
    "version": "1.1.0",
    "summary": "A super simple wrapper around NotificationCenter",
    "homepage": "https://github.com/sobri909/SwiftNotes",
    "authors": {
        "Matt Greenfield": "[email protected]"
    },
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "source": {
        "git": "https://github.com/sobri909/SwiftNotes.git",
        "tag": "1.1.0"
    },
    "source_files": "SwiftNotes/*.swift",
    "platforms": {
        "ios": "10.0"
    },
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This