<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">On 3 Nov 2016, at 8:37 PM, Erica Sadun via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> <span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">private</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">enum</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>StringEnum:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>one, two, three }</span></div><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> <span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">public</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">init</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(strings: [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">String</span><span class="" style="font-variant-ligatures: no-common-ligatures;">]) {</span></div><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> <span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>set =<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">MyOptionSet</span><span class="" style="font-variant-ligatures: no-common-ligatures;">()</span></div><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> strings.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">flatMap</span><span class="" style="font-variant-ligatures: no-common-ligatures;">({<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">StringEnum</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(rawValue: $0) })</span></div><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> .</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">flatMap</span><span class="" style="font-variant-ligatures: no-common-ligatures;">({<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">MyOptionSet</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(rawValue:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">1</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span><< $0.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">hashValue</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) })</span></div><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> .</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">forEach</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{ set.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">insert</span><span class="" style="font-variant-ligatures: no-common-ligatures;">($0) }</span></div><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal; color: rgb(79, 129, 135);"><span class="" style="font-variant-ligatures: no-common-ligatures;"> <span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures;">_rawValue</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>= set.</span><span class="" style="font-variant-ligatures: no-common-ligatures;">rawValue</span></div><div class="" style="font-family: Menlo; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> }</span></div></div></blockquote><br class=""></div><div class="">I’m curious about relying on the hash value of an enum case being its declaration-order index. A sage (<a href="http://ericasadun.com/2015/07/12/swift-enumerations-or-how-to-annoy-tom/" class="">http://ericasadun.com/2015/07/12/swift-enumerations-or-how-to-annoy-tom/</a>) warns that this is an implementation detail. I haven’t seen anything saying it is API. Has it been resolved?</div><div class=""><br class=""></div><div class="">It’s the most plausible implementation, but I’d think code that relies on case order would break silently (likely at widely-separated locations) if a case were inserted or removed. That suggests to me it’s not possible to regularize this behavior.</div><div class=""><br class=""></div><div class="">Folkloric API (like <font face="Menlo" class="" style="font-size: 12px;">SEL</font> ↔︎ <font face="Menlo" class="" style="font-size: 12px;">char*</font> in ObjC) makes me itch.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>— F</div><div class=""><br class=""></div></div></body></html>