> On Oct 11, 2016, at 4:42 PM, Braeden Profile via swift-evolution
> <[email protected]> wrote:
>
> enum RectSize
> {
> let height:Int
> let width:Int
> case small(width: 30, height: 30)
> case medium(width: 60, height: 60)
> case large(width: 120, height: 120)
> }
I like the concept, but this doesn’t seem as flexible as it could be, and could
get ugly when mixing these defaults with enum associated values. How about
dynamic properties instead? Something like:
enum RectSize {
var height: Int { get }
var width: Int { get }
case small {
height { return 30 }
width { return 30 }
}
case medium {
height { return 60 }
width { return 60 }
}
case large {
height { return 120 }
width { return 120 }
}
case custom(width: Int, height: Int) {
height { return height }
width { return width }
}
}
(syntax not exact; this is pseudocode, modify the syntax as appropriate)
This would keep the property implementations separate from the associated
values, and would also allow for the computed properties to do more complex
calculations if necessary.
Charles
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution