Skip to content

[SR-30] Enumerations could have a "allValues" property #42653

@swift-ci

Description

@swift-ci
Previous ID SR-30
Radar rdar://problem/17102392
Original Reporter RuiCarneiro (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 6
Component/s
Labels Improvement, LanguageFeatureRequest
Assignee @CodaFi
Priority Medium

md5: 6f9747e0e0648c9bf5fee84b0f66cd7f

relates to:

  • SR-3050 enum cases should be enumerable

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.

Metadata

Metadata

Assignees

Labels

compilerThe Swift compiler itselfenumFeature → type declarations: Swift enumeration declarationsfeatureA feature request or implementationimprovementswift evolution implementedFlag → feature: A feature that was approved through the Swift evolution process and implemented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions