> On May 10, 2017, at 12:58 AM, Nicholas Maccharoli via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> Swift-Evolution, 
> 
> I'm sorry if this has been brought up before but is there a reason why there 
> is no built-in way of getting the number of cases an enum defines?
> 
> Given something like: enum MyEnum { case foo, bar, baz }
> 
> It would be nice to get the number of cases this enum defines, something like:
> 
>     MyEnum.count
> 
> Looking forward to hearing back about this!

We're way ahead of you:

* Discussion on this topic started in the early months of swift-evolution.

* We decided it'd be much more useful to instead have an `allCases` or 
`allValues` collection attached to the type.

* We've had a proposal for such a feature for the better part of a year.

* But the stars have never aligned to actually get it into the compiler, so 
it's never gotten past the initial proposal stage. (First it was waiting on new 
features that should land in Swift 4; then it didn't really fit with Swift 4's 
goals.)

Here's the most recent pull request for the proposal: 
<https://github.com/apple/swift-evolution/pull/114>

-- 
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to