[swift-evolution] [Proposal] Allow enumerating cases in enumerations

Vladimir.S svabox at gmail.com
Mon Jul 4 14:02:06 CDT 2016


On 04.07.2016 21:21, Brent Royal-Gordon via swift-evolution wrote:
>> On Jul 4, 2016, at 10:43 AM, Leonardo Pessoa <me at lmpessoa.com> wrote:
>>
>> My issue with this being opt-in is third-party libraries.
>
> That's why we have retroactive modeling. :^)
>
> 	import SomeEnumKit
> 	extension SomeEnum: ValuesEnumerable {}
>
> You can extend another module's public enum to add conformance to a protocol, and there's no reason it can't generate the code in your module instead of theirs.
>

Yes, but I can't understand, why not give this ability to each enum? It 
seems like this feature is a very basic thing that enum must(IMO) to have.
What kind of overhead this will generate? Static function or property that 
returns array as I understand should not generate any impact on memory 
required to store each separate *instance* of enum. I don't believe that 
adding a number of bytes to enum *type* to implement .allValues(or whatever 
named) will have any difference for total application/framework.


More information about the swift-evolution mailing list