Right. I don't think there's any plan currently to allow enum case declarations of reserved keywords without backticks. The reasoning, IIUC, was that use sites were far more common and in that context cases could be distinguished by the leading dot. By contrast, declarations are made only once.
FWIW, this is implemented for all keywords and not just `default`, so `.class` or even `.case` should work right now too. It seemed like the core team wanted general solutions that can be implemented for all keywords, and a general solution for declaring enum cases without backticks is probably not possible, I think? On Fri, Jun 17, 2016 at 16:57 E. Maloney via swift-evolution < [email protected]> wrote: > It looks like it’s not-quite-done for enum cases in Xcode 8: You can’t > declare an enum with a case named “default” without escaping the name. > However, it looks like you can refer to an enum case named “default” using > simply “.default”, which I didn’t realize. (I had mistakenly assumed the > escaping rule would be consistent between the enum declaration and the > use-site. Silly me.) > > Either way, it would be great if you could use “default” as a name > universally, especially since it’s a pretty common name to want to use. > > > > On Jun 17, 2016, at 1:50 PM, Jacob Bandes-Storch <[email protected]> > wrote: > > > > Isn't this already done, at least for enum cases? I'm pretty sure I've > seen discussion of this before, and I thought it might've gotten > implemented. > > On Fri, Jun 17, 2016 at 1:45 PM E. Maloney via swift-evolution < > [email protected]> wrote: > > While upgrading to Swift 3, I noticed that I had a few enums with cases > named .Default that, after being converted to lowercase, now need to be > rendered using the ugly .`default` notation. > > > > I also noticed something similar while reading the docs for > NotificationCenter (the NSNotificationCenter replacement, that is, not the > NotificationCenter that governs the notification center UI); “default” > can’t be used as a function name without escaping, so the declaration is: > > > > class func `default`() > > > > It seems to me that in the case of function names and enum cases, the > parser should be able to unambiguously distinguish between the Swift > keyword “default” and a user-defined name “default”, since IIRC the keyword > “default” can only be used in parameter lists for generated headers and as > the last item in a switch statement. > > > > (Perhaps this is also another argument in favor of using “case _:” in > place of “default:” in a switch statement.) > > > > What do you think? Is there any reason this *wouldn’t* be feasible? > > _______________________________________________ > > swift-evolution mailing list > > [email protected] > > https://lists.swift.org/mailman/listinfo/swift-evolution > > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution >
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
