[swift-evolution] Working with enums by name

Leonardo Pessoa me at lmpessoa.com
Wed Jun 1 05:08:59 CDT 2016

Yes, you can do all this but you still have to do everything yourself by hand. Dictionary, plist, it even init as my initial example but you are the one responsible to control when e.g. you add a new value or rename another.

My proposal causes no big changes and no big overload on the compiler; it just adds an init method to find the equivalent enum value for a string. And yes this feature becomes a lot more interesting should the idea of using tuple typed enums goes forward but they are completely independent.


-----Original Message-----
From: "Patrick Smith" <pgwsmith at gmail.com>
Sent: ‎01/‎06/‎2016 04:52 AM
To: "Brent Royal-Gordon" <brent at architechies.com>
Cc: "Leonardo Pessoa" <me at lmpessoa.com>; "Swift-evolution" <swift-evolution at swift.org>
Subject: Re: [swift-evolution] Working with enums by name

I had no idea you could do this!!

> On 1 Jun 2016, at 12:32 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
> Who said anything about repeating the name?
> Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.30). Type :help for assistance.
>  1> enum Planet: String { case mercury, venus, earth, mars, jupiter, saturn, uranus, neptune }
>  2> Planet.mercury.rawValue
> $R0: String = "mercury"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160601/59a71108/attachment.html>

More information about the swift-evolution mailing list