<font size="2"><span style="background-color:rgba(255,255,255,0)">If you wrote:</span></font><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"> enum Ex { case one, two, three }</span></font></div><div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)">And the compiler translated that into the equivalent of:</span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div><ul style="margin:0px;padding:0px;list-style:none;width:auto"><li style="border-left-style:none;margin-left:4em"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">struct</code> Ex <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">: </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"><a href="http://swiftdoc.org/v2.2/protocol/OptionSetType" target="_blank" style="text-decoration:underline;background-image:none!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;padding:0px!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">OptionSetType</a></code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">{</code></span></font></li><li style="border-left-style:none;margin-left:4em"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"> let <font face="Helvetica Neue, Helvetica, Arial, sans-serif">rawValue</font></code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">: U</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"><a href="http://swiftdoc.org/v2.2/type/Int" target="_blank" style="text-decoration:underline;background-image:none!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;padding:0px!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">Int</a></code></span></font></li><li style="border-left-style:none;margin-left:4em"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"> </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">init</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">(rawValue</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">: U</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"><a href="http://swiftdoc.org/v2.2/type/Int" target="_blank" style="text-decoration:underline;background-image:none!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;padding:0px!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">Int</a></code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">) { </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">self</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">.rawValue</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">= rawValue</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">}</code></span></font></li><li style="border-left-style:none;margin-left:4em"><font size="2"><span style="background-color:rgba(255,255,255,0)"> </span></font></li><li style="border-left-style:none;margin-left:4em"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"> </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">static</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">let</code> one <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">= Ex</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">(rawValue: </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">1</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">)</code></span></font></li><li style="border-left-style:none;margin-left:4em"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"> </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">static</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">let</code> two <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">= Ex</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">(rawValue: </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">2</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">)</code></span></font></li><li style="border-left-style:none;margin-left:4em"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"> </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">static</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">let three = Ex(rawValue: 4)</code></span></font></li><li style="border-left-style:none;margin-left:4em"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important"> </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">static</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">let</code> values<code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">: Ex</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">= [one, two, three</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">]</code></span></font></li><li style="border-left-style:none;margin-left:4em;padding-bottom:0px!important"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important;background-color:rgba(255,255,255,0)"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3">}</font></code></li></ul><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)">This would allow set behaviour which I found very handy in Java and be as robust as any other option set.</span></font></div><div><font size="2"><span style="background-color:rgba(255,255,255,0)"><br></span></font></div><div><font size="2" style="background-color:rgba(255,255,255,0)">PS Int only applicable for < 64 cases. Need BigInt for others. </font></div></div></div><br>On Sunday, 24 April 2016, John McCall via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Apr 22, 2016, at 11:48 PM, Jacob Bandes-Storch <<a href="javascript:_e(%7B%7D,'cvml','jtbandes@gmail.com');" target="_blank">jtbandes@gmail.com</a>> wrote:</div><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 22, 2016 at 11:34 PM, John McCall <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','rjmccall@apple.com');" target="_blank">rjmccall@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><blockquote type="cite"><div>On Apr 22, 2016, at 11:11 PM, Jacob Bandes-Storch <<a href="javascript:_e(%7B%7D,'cvml','jtbandes@gmail.com');" target="_blank">jtbandes@gmail.com</a>> wrote:</div><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 22, 2016 at 10:50 PM, John McCall <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','rjmccall@apple.com');" target="_blank">rjmccall@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><div><br></div></div></div></div>I have not been following this discussion, but I would be extremely antsy about guaranteeing any particular representation for the set of values. Guaranteeing a contiguous array implementation seems like a really bad idea, especially if that's taken to mean that we're going to actually provide a static global array. But there's no way to avoid providing a public API, because a public conformance itself implies a public API with some level of corresponding overhead.</div></blockquote><div><br></div><div>A "compiler magic" version of the feature, like #allValues(MyEnum), could generate a static array *internal* to the caller's module, but I'm sure there are implications or details of this which I'm not aware of.</div></div></div></div></div></blockquote><div><br></div></span>That cannot be reconciled with resilience. The caller cannot reliably know the set of stored cases; only the defining module can.</div><div><br></div><div>For similar reasons, only the defining module can be allowed to magically derive a conformance to your protocol, if indeed it's done with a protocol.</div></div></blockquote><div><br></div><div>What should/can this mean for enums imported from Obj-C, via other modules, or bridging headers / custom module maps? In these cases, the defining module has no Swift code. Is there a way to do it with pre-existing metadata in the module?</div></div></div></div>
</div></blockquote></div><br><div>Imported declarations are always something of a special case for this sort of thing.</div><div><br></div><div>It is possible to import an enum as "open", meaning that the library reserves the right to add new enumerators; it would never be possible to make such a type ValuesEnumerable, at least via the built-in magic. But otherwise we could certainly give imported enums this conformance by default if we wanted to.</div><div><br></div><div>John.</div></div></blockquote><br><br>-- <br>-- Howard.<br>