[swift-evolution] [Proposal] Enums with stored properties

Mateusz Malczak mateusz at malczak.info
Mon Oct 10 14:07:11 CDT 2016


For simple structs this is already possible (see this example:
https://swiftlang.ng.bluemix.net/#/repl/57fb8e3e4f9bcf25fdd415cd).
If we focus on more complex cases where properties of Any? type are
allowed I think this approach could do the trick...
but still I would like to be able to access properties without using rawValue
--
| Mateusz Malczak
+-------------------------------
| mateusz at malczak.info
| http://malczak.info


2016-10-10 20:54 GMT+02:00 J.E. Schotsman via swift-evolution
<swift-evolution at swift.org>:
>
> On 10 Oct 2016, at 15:46,Mateusz Malczak wrote:
>
>
> t a good illustration of what I would like to be able to define with
> my proposed feature.
> But instead to creating a class/struct to in switch case I would like
> enumeration type to be able to carry that information within its cases
>
>
> Wouldn’t it be more natural to allow structs as raw values?
>
> For example
>
> struct MyRect
> {
> var height:Int
> var width:Int
> var area:Int {return height:Int*width}
> }
>
> enum RectSizes: MyRect
> {
> case Small(30,30)
> case Medium(60,60)
> case Large(120,120)
> }
>
> let smallArea = RectSizes.Small.rawValue.area
>
> Jan E.
>
> _______________________________________________
> 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