I noticed that the Swift 3 converter wrapped all of my NSNotification notification names in Notification.Name(rawValue: ) at the call sites, but I already declare my notification names, and so this conversion results in bulky call sites. I am wondering if there is a new best practice that I should be following instead that makes my notification names more consistent with system notifications, to keep my call sites clean.
For example, I have a notification name previously declared like this:
public let kContentAddedNotification = "contentAdded"
As of Swift 3, this causes the call site look like this:
NotificationCenter.default().post(name: Notification.Name(rawValue: kContentAddedNotification), object: self)
Based on how the system notifications are being synthesized, it would appear that I should declare notification names more like this:
public extension Notification.Name {
public static let contentAdded = Notification.Name("ContentAdded")
}
In the call site, it would appear like this:
NotificationCenter.default().post(name: .contentAdded, object: self)
So, is this the right syntax for declaring a notification name in Swift 3?