[swift-evolution] List of all Enum values (for simple enums)

Jacob Bandes-Storch jtbandes at gmail.com
Tue Dec 8 23:53:16 CST 2015

Enums are often used without associated values:

    enum Attribute { case Title, Date }
    enum Style { case Dark, Light }

In such cases, it's very useful to be able to iterate over all possible
values. But you have to do it manually:

    extension Attribute {
        static var allValues: [Attribute] {
            return [.Title, .Date]  // imagine this x100, and not
autogenerated :(

It would be nice if the compiler generated this for us. It doesn't have to
be an Array, but any kind of SequenceType. Maybe something like
"StaticCollection". Of course, this doesn't work in the general case, but I
think simple enums are common enough that it might be worth doing.


Jacob Bandes-Storch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151208/e5afe44a/attachment.html>

More information about the swift-evolution mailing list