An Elegant Notification.Name Extension in Swift 3
In the new Swift 3 there is now a different initializer for NSNotification (now simply Notification; the NS prefix was dropped):
struct Config {
static let ShouldCloseBrowserNotification = "ShouldCloseBrowserNotification"
}
let notification = Notification(
name: Notification.Name(rawValue: Config.ShouldUpdateDialogNotification),
object: nil,
userInfo: nil
)
NotificationCenter.default.post(notification)
The name parameter does not look very nice now. But you can extend Notification.Name to make it look better:
extension Notification.Name {
static let shouldCloseBrowserNotification = Notification.Name("ShouldCloseBrowserNotification")
}
let notification = Notification(
name: .ShouldUpdateDialogNotification,
object: nil,
userInfo: nil
)
NotificationCenter.default.post(notification)
UIKit itself is structured in roughly the same way:

// ─── EOF ──────────────────────────────────────────────────