Xcode Version 6.0 (6A279r): [Swift] Add possibility to get / iterate over the members of an enumeration
| Originator: | janoschhildebrand | ||
| Number: | rdar://17622900 | Date Originated: | 10-Jul-2014 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.0 (6A279r) |
| Classification: | Feature Request | Reproducible: | NA |
Summary: Enumeration should allow one to retrieve the members of the enumeration. For enumerations with raw values this might have obvious benefits depending on what the raw value represents and is present in many other programming languages. For enumerations without raw values it is somewhat more difficult but might still be beneficial. For example in the "Swift Tour" in the "The Swift Programming Language" book, an enumeration representing the suits of playing cards is constructed along with an enumeration representing the values (ranks) possible within each suit. Later on the reader is asked to construct a full set of cards, i.e. each possible combination of suit and rank. This would be much easier if one could simply iterate over the members of both enumerations, for example one could trivially implement this using two for-in loops without needing to know the actual members of the enumerations. One way might be an exposed collection on enumeration types that contains the individual members, another would be that the Type would conform to the Sequence protocol to enable for-in iteration over the members. For enumerations with raw values this should be easy to implement and should be made available. Likewise, for enumerations without raw values but containing no members with associated values this should be possible as well. For enumerations with associated values this would be trickier and might require a different approach as the enumeration members with associated values can in theory have many actual representations/states/values. So it is not at all clear what an enumeration type would return as a representation of such a member. In the short term it might be feasible to simple not make this functionality available on enumerations containing members with associated values until a clean solution is found. Steps to Reproduce: Expected Results: Actual Results: Version: Xcode 6 - Beta 3 (6A254o) Swift version 1.0 (swift-600.0.38.7) OS X 10.10 (14A283o)
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!