[SR-30] Enumerations could have a "allValues" property #42653
Labels
compiler
The Swift compiler in itself
enum
Feature → type declarations: Swift enumeration declarations
feature
A feature request or implementation
improvement
swift evolution implemented
Flag → feature: A feature that was approved through the Swift evolution process and implemented
Additional Detail from JIRA
md5: 6f9747e0e0648c9bf5fee84b0f66cd7f
relates to:
Issue Description:
Sometimes, it's convenient to have an allValues property for an enum that automatically generates a collection with all possible elements.
eg:
{{enum Fruits { case Apple, Orange, Peach, Banana }
for fruit in Fruits.allValues {
// ...
}}}
{color:red}On another note, it would be handy to have a reverse function for the rawValue propriety
eg:
{{enum Fruits : Int { case Apple = 0, Orange ... }
let fruit : Fruits? = Fruits.reverseRawValue(1)
// fruit == Fruits.Orange}}{color}
Thanks, Kevin Ballard.
The text was updated successfully, but these errors were encountered: