> While converting to Swift3, my biggest hurdle was figuring out what to do 
> with a custom NSNotification. In Objective-C, it’s a plain NSString, and the 
> same in Swift2.
> 
> I assumed in Swift3 that it worked like ErrorProtocol and errors as enums, 
> but as it turns out, you need to create a custom instance of 
> Notification.Name(“MyNotificationName”). This does not seem very Swifty, and 
> I think it would work better if there was a NotificationNameProtocol and you 
> could create enums with String raw values.

The migrator constructs the Notification.Name instances at the call site, but I 
believe the *actual* intent is that you should assign them to a constant—either 
one in your own type:

        // Old
        let MyClassWillFooNotificationName = "MyClassWillFoo"
        // New:
        class MyClass: … {
                static let WillFoo = Notification.Name("MyClass.WillFoo")
        }

Or in an extension to `Notification.Name` itself.

-- 
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to