[swift-evolution] [Idea] `enum` case count feature

Brent Royal-Gordon brent at architechies.com
Wed May 10 03:08:21 CDT 2017


> On May 10, 2017, at 12:58 AM, Nicholas Maccharoli via swift-evolution <swift-evolution at 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170510/b933f21c/attachment.html>


More information about the swift-evolution mailing list