Swift: enums should have an allCases property which is a Set of all cases
| Originator: | andrew | ||
| Number: | rdar://21401702 | Date Originated: | 16-Jun-2015 03:22 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | 2.0 |
| Classification: | Feature (New) | Reproducible: | Always |
Summary: Sometimes it is useful to be able to iterate over all cases of an enum. Currently there is no clean way to do this, as per this blog post: <http://www.swift-studies.com/blog/2014/6/10/enumerating-enums-in-swift> It would be much cleaner if there was an allCases property which returns a Set of all cases (Set rather than Array, because order is not defined and it should be impossible to have the same enum case more than once). Steps to Reproduce: i) Try and iterate over all cases of an enum. ii) Google the problem iii) Observe a multitude of dirty hacks Expected Results: There should be an elegant way to do this. Actual Results: Dirty hacks. Regression: N/A Notes: Best solutions I’ve come across as yet (which is brittle and prone to breakage when someone adds a new case): http://www.swift-studies.com/blog/2014/6/10/enumerating-enums-in-swift
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!