SwiftyNotifications is an easy and type-safe way to work with Notification.Name in Swift.
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
}