Enum class and instance methods to aid iteration over valid values.
| Originator: | GriotSpeak | ||
| Number: | rdar://17412547 | Date Originated: | 2014-06-22 |
| Status: | Closed as Duplicate of 17102392 | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: |
Summary:
Enum type iteration could be aided by predecessor and successor instance methods and/or an allValues class method.
Consider an enum defined as follows
`enum SomeEnum : Int {
case Foo = 0
case Bar
case Baz = 34
}`
A simple and safe way to iterate through all valid enum values does not exist without hard coding an array somewhere in our code. Providing a built in means to accomplish this would be a cherry on top of an already potent enum type.
Steps to Reproduce:
let myVal1:SomeEnum = .Foo
let myVal2 = myVal1.pred // pred should return (optional<SomeEnum>)
myVal2 // should evaluate to SomeEnum.Bar
let myVal3 = myVal1.succ // succ should also return (optional<SomeEnum>)
myVal3 // should evaluate to SomeEnum.Foo
let allValues = SomeEnum.allValues() // should return [Foo, Bar, Baz]
Expected Results:
let myVal1:SomeEnum = .Foo
let myVal2 = myVal1.pred // pred should return (optional<SomeEnum>)
myVal2
let myVal3 = myVal1.succ // succ should also return (optional<SomeEnum>)
myVal3
let allValues = SomeEnum.allValues() // should return SomeEnum[]
allValues
Actual Results:
let myVal1:SomeEnum = .Foo
let myVal2 = myVal1.pred // pred should return (optional<SomeEnum>)
myVal2 // should evaluate to SomeEnum.Bar
let myVal3 = myVal1.succ // succ should also return (optional<SomeEnum>)
myVal3 // should evaluate to SomeEnum.Foo
let allValues = SomeEnum.allValues() // should return SomeEnum[]
allValues // should evaluate to [SomeEnum.Foo, SomeEnum.Bar, SomeEnum.Baz]
Version:
Notes:
Configuration:
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!