<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="-ms-word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">Patrick, I never said the order of the enum was intrinsic. If the offset of the case were the truth of the enum as you said enums would be ordinal types and you could do tests like "Planet.Mercury > Planet.Venus" without any extra code. But enums are nominal types not ordinal types so you can only distinguish the different values but they have no particular order or any other property. Two simple examples of nominal types are colours and cardinal points. Do they have any particular order? That's how enums are implemented in Swift (as a nominal type) and that's another reason why working with case names makes even more sense.<br><br>L</div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:pgwsmith@gmail.com">Patrick Smith</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">02/06/2016 11:18 PM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:me@lmpessoa.com">Leonardo Pessoa</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:brent@architechies.com">Brent Royal-Gordon</a>; <a href="mailto:swift-evolution@swift.org">swift-evolution</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [swift-evolution] Working with enums by name</span><br><br></div><div>From what I understand, enums normally are represented internally by an offset — that is their truth. With RawRepresentable enums, you are saying “no, I want the truth to be something else”. But it seems that they are still represented internally by an offset, so you can’t reorder a RawRepresentable enum’s cases and maintain ABI compatibility either.</div><div><br></div><div>So what you are saying about the order of cases being an intrinsic part of an enum does make sense. I’m not sure if can still lead to confusing / fragile code though.</div><div><br></div><div>Patrick</div><div><br></div><br><div><blockquote type="cite"><div>On 2 Jun 2016, at 10:17 PM, Leonardo Pessoa <<a href="mailto:me@lmpessoa.com">me@lmpessoa.com</a>> wrote:</div><br class="Apple-interchange-newline"><div><div><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">There are several ways to solve this, which IMO is a basic functionality of enums, writing code that is currently possible and works. But that's the issue, you still have to write code to have a basic functionally. I don't remember not being able to do this out-of-the-box in any language I worked with.<br><br>L</div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:pgwsmith@gmail.com">Patrick Smith</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">02/06/2016 02:07 AM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:brent@architechies.com">Brent Royal-Gordon</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:me@lmpessoa.com">Leonardo Pessoa</a>; <a href="mailto:swift-evolution@swift.org">swift-evolution</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [swift-evolution] Working with enums by name</span><br><br></div>Great points Brent. I think the ValuesEnumerable method would be the most straight forward. Also, the number of cases are likely only going to be in range of 6–20, so iterating would be fine I think. People can create something like `Dictionary(Planet.allValues.enumerated().lazy.map{ ($1, $0) })` (I think that’s right) if they really need.<br><br><br>> On 2 Jun 2016, at 2:40 PM, Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>> <br>> Or the `ValuesEnumerable` proposal would give you a convenient, though slightly slow, way to do two-way lookup by order:<br>> <br>>         enum Planet: String, ValuesEnumerable {<br>>                 var order: Int {<br>>                         return Planet.allValues.index(of: self)!<br>>                 }<br>>                 init(order: Int) {<br>>                         self = Planet.allValues[order]<br>>                 }<br>>                 case mercury, venus, …<br>>         }<br><br></div></div></blockquote></div><br></body></html>