[swift-evolution] [Proposal] Enums with stored properties
Adrian Zubarev
adrian.zubarev at devandartist.com
Mon Oct 10 13:33:03 CDT 2016
I haven’t followed the whole topic, but I myself always wished for stored properties on Swift enums.
I’d like to throw an idea in the room.
How about to a two type enums? By that I mean something like this:
enum Enum : RawType, StoreType {
case a = (rawInstance1, storeInstance1)
case b = (rawInstance2, storeInstance2)
case c = rawInstance3, storeInstance3 // or not tuple like?
}
let instance = Enum.a
instance.rawValue // would be rawInstance1
instance.value // would be storeInstance1
StoreType could be anything (even another two type enum).
It would be interesting to read what you thing of that simple model. Plus should .value be mutable? Maybe we could communicate that somehow.
Or we could simply allow tuples on enums where the first item is always the RawType of the enum?!
--
Adrian Zubarev
Sent with Airmail
Am 10. Oktober 2016 um 19:32:20, Kenny Leung via swift-evolution (swift-evolution at swift.org) schrieb:
This is the way Java enumerations work.
https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
I think it is a good model, and I think Swift enumerations should also work the same way.
An enumeration is a finite set of things. It’s really inconvenient to have to limit those things to have only a single attribute.
-Kenny
_______________________________________________
swift-evolution mailing list
swift-evolution at swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161010/a1cb7e9c/attachment.html>
More information about the swift-evolution
mailing list