This is mentioned in Gabriel's proposal: > Implement a native .cases static var for all enumerations without associated > values
But as has been mentioned in the discussion, this was mentioned by Brent: > In previous discussions, the core team specifically asked that this be opt-in > so that types which don't want it don't need to "pay" for it. > On Jul 5, 2016, at 12:43 PM, James Campbell <[email protected]> wrote: > > Maybe a way we could opt in is by only doing this for enums with out turples? > > i.e > > enum ABTestingBrah { > > case A > case B > > } > > I'm not sure if enums that take turples would need this functionality. > > ___________________________________ > > James⎥Head of Trolls > > [email protected] <mailto:[email protected]>⎥supmenow.com > <http://supmenow.com/> > Sup > > Runway East > > > 10 Finsbury Square > > London > > > EC2A 1AF > > > On 5 July 2016 at 11:39, Charlie Monroe <[email protected] > <mailto:[email protected]>> wrote: > Example: > > enum MediaKind { > case HomeVideo, Movie, MusicVideo, TVShow > > var localizedName: String { ... } > } > > let popUpButton: NSPopUpButton = ... > for kind in MediaKind.allKinds { > popUpButton.addItemWithTitle(kind.localizedName) > } > > And many, many more. > > >> On Jul 5, 2016, at 12:33 PM, James Campbell via swift-evolution >> <[email protected] <mailto:[email protected]>> wrote: >> >> Would love a real life scenario of why you would need this. >> >> ___________________________________ >> >> James⎥Head of Trolls >> >> [email protected] <mailto:[email protected]>⎥supmenow.com >> <http://supmenow.com/> >> Sup >> >> Runway East >> >> >> 10 Finsbury Square >> >> London >> >> >> EC2A 1AF >> >> >> On 4 July 2016 at 02:36, Gabriel Lanata via swift-evolution >> <[email protected] <mailto:[email protected]>> wrote: >> Hello, this has been proposed multiple times before in different ways. >> >> Link to detailed proposal draft: >> https://github.com/gabriellanata/swift-evolution/blob/master/proposals/NNNN-allow-enumerating-cases-in-enumerations.md >> >> <https://github.com/gabriellanata/swift-evolution/blob/master/proposals/NNNN-allow-enumerating-cases-in-enumerations.md> >> >> 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. >> >> The proposed solution is to implement a native `.cases` static var for all >> enumerations without associated values. This would provide a strict >> type-safe way of enumerating though the possible cases without risking >> runtime errors. The resulting code is a lot cleaner and less prone to errors >> caused by forgetting to update the hardcoded values when modifying cases. >> >> Resulting code: >> >> enum PokemonType { >> case Fire, Grass, Water, Wind >> } >> for pokemonType in PokemonType.cases { >> // Do stuff >> } >> PokemonType.cases.count // Returns 4 >> >> >> ------- >> Gabriel >> >> >> _______________________________________________ >> swift-evolution mailing list >> [email protected] <mailto:[email protected]> >> https://lists.swift.org/mailman/listinfo/swift-evolution >> <https://lists.swift.org/mailman/listinfo/swift-evolution> >> >> >> _______________________________________________ >> swift-evolution mailing list >> [email protected] <mailto:[email protected]> >> https://lists.swift.org/mailman/listinfo/swift-evolution >> <https://lists.swift.org/mailman/listinfo/swift-evolution> > >
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
