[swift-evolution] Working with enums by name

Paul Cantrell cantrell at pobox.com
Tue May 31 17:03:08 CDT 2016

> On May 31, 2016, at 4:48 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> |   enum Planet : Int {
>> |      case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
>> |
>> |      init?(caseName name : String) {
> The compiler actually does this already through RawRepresentable if you put `String` as your raw type. So what's the use case for this? Code which needs both a non-String rawValue *and* needs to look up cases by name? How common do you think that is?

How about a LogCategory enum:

• whose name is printed with each log entry (and thus wants a String raw type),
• which can be configured from command line or config file (and thus wants string-based lookup), but
• also wants OptionSetType-like behavior (and thus an Int raw type).


More information about the swift-evolution mailing list