<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=""><div class="">Example:</div><div class=""><br class=""></div><div class="">enum MediaKind {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case HomeVideo, Movie, MusicVideo, TVShow</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var localizedName: String { ... }</div><div class="">}</div><div class=""><br class=""></div><div class="">let popUpButton: NSPopUpButton = ...</div><div class="">for kind in MediaKind.allKinds {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>popUpButton.addItemWithTitle(kind.localizedName)</div><div class="">}</div><div class=""><br class=""></div><div class="">And many, many more.</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 5, 2016, at 12:33 PM, James Campbell via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family: arial, helvetica, sans-serif; font-size: small;">Would love a real life scenario of why you would need this.</div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><p class=""><b class=""><font color="#cc0000" class="">___________________________________</font></b></p><p class=""><b class="">James⎥Head of Trolls</b></p><p class=""><b class=""><font color="#cc0000" class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a>⎥<a href="http://supmenow.com/" target="_blank" class="">supmenow.com</a></font></b></p><p class=""><b class=""><font size="2" class="">Sup</font></b></p><p class=""><b class=""><font size="2" class="">Runway East
</font></b></p><p class=""><b class=""><font size="2" class="">10 Finsbury Square</font></b></p><p class=""><b class=""><font size="2" class="">London</font></b></p><p class=""><b class=""><font size="2" class="">
EC2A 1AF </font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br class=""><div class="gmail_quote">On 4 July 2016 at 02:36, Gabriel Lanata via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_quote"><div dir="ltr" class=""><div class="gmail_quote"><div dir="ltr" class=""><div class="gmail_quote"><div dir="ltr" class=""><div class="">Hello, this has been proposed multiple times before in different ways. </div><div class=""><div class=""><font color="#333333" class=""><br class="">Link to detailed proposal draft:</font></div><a href="https://github.com/gabriellanata/swift-evolution/blob/master/proposals/NNNN-allow-enumerating-cases-in-enumerations.md" target="_blank" class="">https://github.com/gabriellanata/swift-evolution/blob/master/proposals/NNNN-allow-enumerating-cases-in-enumerations.md</a></div><div class=""><br class=""></div><div class="">It is currently not possible to enumerate through all the possible cases of an enumeration object without adding a hardcoded value or recurring to unsafe workarounds. The proposal is to add a method of obtaining an array or set of all the possible cases natively for enumerations without associated values.</div><div class=""><br class=""></div><div class=""><div class="">The proposed solution is to i<span style="line-height:1.5" class="">mplement a native `.cases` static var for all enumerations without associated </span><span style="line-height:1.5" class="">values. This would provide a strict type-safe way of enumerating though the </span><span style="line-height:1.5" class="">possible cases without risking runtime errors. The resulting code is a lot </span><span style="line-height:1.5" class="">cleaner and less prone to errors caused by forgetting to update the hardcoded </span><span style="line-height:1.5" class="">values when modifying cases.</span></div><div class=""><br class=""></div><div class=""><div class=""><div class="">Resulting code:</div><div class=""> </div></div></div><div class=""> enum PokemonType {</div><div class=""> case Fire, Grass, Water, Wind</div><div class=""> }</div><div class=""> for pokemonType in PokemonType.cases {</div><div class=""> // Do stuff</div><div class=""> }</div><div class=""> PokemonType.cases.count // Returns 4</div></div><div class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-------</div><div class="">Gabriel</div><div class=""><br class=""></div></div></div></div></div></div></div></div>
<br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>