How do you create custom notifications in Swift 3?

hexdreamer picture hexdreamer · Jun 18, 2016 · Viewed 48.9k times · Source

In Objective-C, a custom notification is just a plain NSString, but it's not obvious in the WWDC version of Swift 3 just what it should be.

Answer

Cesar Varela picture Cesar Varela · Aug 13, 2016

There is a cleaner (I think) way to achieve it

extension Notification.Name {

    static let onSelectedSkin = Notification.Name("on-selected-skin")
}

And then you can use it like this

NotificationCenter.default.post(name: .onSelectedSkin, object: selectedSkin)