Skip to content

joseph2166/SwiftyNotifications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyNotifications

Swift helpers around Foundation's Notification.Name

SwiftyNotifications is an easy and type-safe way to work with Notification.Name in Swift.

Usage

Notification name objects can be created with string literals:

let somethingDidChange: Notification.Name = "SomethingChanged"

Add observers using block syntax; blocks are guaranteed to always run on the main thread, even if notifications are posted on a different thread.

somethingDidChange.addObserver() { notification in
	// Do something
}

Post notifications thusly:

somethingDidChange.post()

A type-safe generic type with identical syntax is available when using sender objects:

let boolDidChange: Notification.TypeSafeName<Bool> = "BoolChanged"

boolDidChange.post(true) // Must send a Bool

boolDidChange.addObserver() { notification, object in
	// `object` is guaranteed to be a Bool
}

About

An easy way to work with `Notification.Name` in Swift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages