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

Charles Srstka cocoadev at charlessoft.com
Wed Oct 12 14:25:51 CDT 2016


> On Oct 12, 2016, at 12:32 PM, Kevin Nattinger via swift-evolution <swift-evolution at swift.org> wrote:
> 
> or more like a body (some different options for syntax, pick one obviously):
> enum Size {
> 	let height: Int
> 	let width: Int
> 	case small {
> 		height = 30
> 		width = 30
> 	}
> 	case medium: {
> 		.height = 60
> 		.width = 60
> 	}
> 	case large = {
> 		let height = 120
> 		let width = 120
> 	}
> }

I sort of prefer to have a protocol-like syntax for declaring the properties, instead of let, because we’re doing something similar to what protocols do: we’re promising that each of these things will provide the property, although they might do it in different ways. This also avoids the connotation we have with “let” that the property will be a constant, when in actuality it may be dynamically computed and thus there is the possibility for it to be different each time.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161012/306a22a5/attachment.html>


More information about the swift-evolution mailing list