[swift-evolution] Draft Proposal: count property for enum types
Arthur Ariel Sabintsev
arthur at sabintsev.com
Tue Jan 19 19:16:26 CST 2016
Why does it fizzle out? I've seen many posts on the web from developers
looking for a way to return an array of all values from a Swift enum. The
only decent solution I've seen work for enums that have Integer-type raw
values, a la Nate Cook: http://stackoverflow.com/a/27094913/814861
What I always found interesting was how enums play with Switch statements.
As Switch statements need to be exhaustive, they have the ability to check
to see if all cases of the enum have been explicitly declared (or
implicitly via the 'default' case). This makes me think that extending
there should be a trivial way to add this functionality to enums.
On Sun, Jan 17, 2016 at 7:07 AM Brent Royal-Gordon via swift-evolution <
swift-evolution at swift.org> wrote:
> > I propose adding a read-only ‘count’ property to enum types, that
> returns the number of cases; modelled on the API for arrays types.
> Most discussions of this start with a `count` proposal, proceed to an
> `allValues` array or something of the sort, and then fizzle out before
> anyone actually writes a formal proposal. Feel free to break that pattern.
> Brent Royal-Gordon
> swift-evolution mailing list
> swift-evolution at swift.org
Arthur / Sabintsev.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution