[swift-users] What is up with names not being Strings any more in Swift 4?

Hooman Mehr hooman at mac.com
Tue Jul 18 12:37:56 CDT 2017


I think this should be a feature of Xcode to automatically generate / maintain these constants: When you add assets or create interface builder files, a plug-in could take care of generating / updating such constants and you would get auto-complete and type safety for free.

> On Jul 18, 2017, at 3:56 AM, Manfred Schubert via swift-users <swift-users at swift.org> wrote:
> 
> 
>> Am 18.07.2017 um 00:58 schrieb Greg Parker via swift-users <swift-users at swift.org>:
>> 
>> 
>>> On Jul 17, 2017, at 10:01 AM, Nevin Brackett-Rozinsky via swift-users <swift-users at swift.org> wrote:
>>> 
>>> Could / should these types be ExpressibleByStringLiteral?
>> 
>> They should not. We are deliberately discouraging the string literal of the name. The string literal should be in only one place: the definition of the name constant. Everything else should use the constant. The compiler can provide autocompletion and typo detection of the constant. The string literal doesn't get that.
> 
> The thing is, with Notification.Name, you have to use them at least twice. So everybody is creating a constant. And typos in the String that defines the constant don't matter. So this solves the problem. With NSNib however, the default case is to use the name only once. And I would say with NSImage it's probably the same. I don't think people have been defining constants for these when they are only used once. It makes the code unnecessarily longer and more complicated. And a typo in the String that defines the constant matter just as much as a typo in the String literal. So in the default case this doesn't solve a problem.
> 
> 
> Kind regards,
> 
> Manfred
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list