<div dir="ltr">+1. The only thing that I don't like is that it may lead to confusion to novice developers because it only work with "basic" enums i.e. enums without associated values. The same thing happens with protocols with associated types, where you can't use the protocol with associated types as the type of properties, variables or constants like "basic" protocols.<br></div><br><div class="gmail_quote"><div dir="ltr">El dom., 3 jul. 2016 a las 21:58, Saagar Jha via swift-evolution (<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+1 since it makes it easy to get the number of possible enum values, but I thought I'd tell you: there's no "Wind" type in Pokémon. It's "Flying". <br><div class="gmail_quote"><div dir="ltr">On Sun, Jul 3, 2016 at 18:36 Gabriel Lanata via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div>Hello, this has been proposed multiple times before in different ways. </div><div><div><font color="#333333"><br>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">https://github.com/gabriellanata/swift-evolution/blob/master/proposals/NNNN-allow-enumerating-cases-in-enumerations.md</a></div><div><br></div><div>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><br></div><div><div>The proposed solution is to i<span style="line-height:1.5">mplement a native `.cases` static var for all enumerations without associated </span><span style="line-height:1.5">values. This would provide a strict type-safe way of enumerating though the </span><span style="line-height:1.5">possible cases without risking runtime errors. The resulting code is a lot </span><span style="line-height:1.5">cleaner and less prone to errors caused by forgetting to update the hardcoded </span><span style="line-height:1.5">values when modifying cases.</span></div><div><br></div><div><div><div>Resulting code:</div><div> </div></div></div><div> enum PokemonType {</div><div> case Fire, Grass, Water, Wind</div><div> }</div><div> for pokemonType in PokemonType.cases {</div><div> // Do stuff</div><div> }</div><div> PokemonType.cases.count // Returns 4</div></div><div></div><div><br></div><div><br></div><div>-------</div><div>Gabriel</div><div><br></div></div></div></div></div></div></div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>