[swift-evolution] Allowing enum extensions to also be able to expand case options

David Sweeris davesweeris at mac.com
Thu Jun 30 15:04:29 CDT 2016


By itself, this would break switch statements, since they have to be exhaustive.

If anyone has any ideas about how to fix that, I'm all ears.

- Dave Sweeris

> On Jun 30, 2016, at 14:58, Edward Valentini via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> I am finding myself in a situation where the most elegant "swifty" solution would be to allow enum extensions to add to existing case options.  For example lets say I'm using a library that has the following enum defined: 
> 
> enum MyDirection {
>   case east, west
> }
> 
> My app for example also makes use of north and south, so I would love to be able to write: 
> 
> extension MyDirection {
>   case north,south
> }
> 
> In objective c, one would probably have defined constants like MyDirectionEast etc...  these would probably have been mapped to ints or strings so a consumer of this library could have easily extended this to add additional functionality, but using constants like that is not very "swifty"
> 
> I'm curious what the swift community thinks.
> 
> Thank you 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list