[swift-evolution] Working with enums by name
cantrell at pobox.com
Wed Jun 1 16:07:02 CDT 2016
> On Jun 1, 2016, at 2:20 PM, Christopher Kornher via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> On Jun 1, 2016, at 12:53 PM, Paul Cantrell via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> This is the case I was thinking of where the module name comes into play. Drop those enums into a framework, and you’ll get "landed(MyFramework.CoinSide.heads)". Ugh!
> This seems to be more of namespace “import” issue than a problem with enums specifically. Declaring enums within another entity is a useful. I take advantage of qualified naming to make short, possibly non-unique enum names.
Yes, in _code_ fully qualified names are useful.
This thread is the need for unqualified names in _strings_ — for passing to external systems, logging, etc.
The problematic behavior I was pointing out is that enums get converted to a name-only string when they are at the _top_ level of a data structure, but a fully qualified Module.EnumType.caseName when they're _nested_ inside a collection or another enum. AFAIK, there's no way to override this behavior without manually coding a case statement to map enum values to strings. This proposal would solve that.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution