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

Kevin Nattinger swift at nattinger.net
Mon Oct 10 13:58:25 CDT 2016


I would be amenable to that IF we can skip the `.rawValue`, which is, IMO, ugly and repetitive.
> On Oct 10, 2016, at 11:54 AM, J.E. Schotsman via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161010/9139b0f1/attachment.html>


More information about the swift-evolution mailing list