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

J.E. Schotsman jeschot at xs4all.nl
Mon Oct 10 13:54:42 CDT 2016


> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161010/5ce0ecbb/attachment.html>


More information about the swift-evolution mailing list