Skip to content

sobri909/SwiftNotes

Repository files navigation

SwiftNotes

A super simple wrapper aroundNotificationCenter.

Setup

pod'SwiftNotes'

Or just dropSwiftNotes.swiftinto your project.

UIKit Notification Examples

UIKeyboard Notifications

when(.UIKeyboardDidShow){notein
// do stuff
}

UIApplication Notifications

when(.UIApplicationDidBecomeActive){_in
// do stuff
}

Custom Notifications

Define A Custom Notification

// define the custom event name
extensionNSNotification.Name{
staticletsomethingHappened=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
}