<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 10 Oct 2016, at 20:34, Mateusz Malczak &lt;<a href="mailto:mateusz@malczak.info" class="">mateusz@malczak.info</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><blockquote type="cite" class="">I know, but what I'm saying is that this problem could be solved in the<br class="">multiple values case by allowing tuples as raw values for enums, since that<br class="">would allow you to specify both width and height. So it'd look something<br class="">like this:<br class=""></blockquote><br class="">We have three different possible solution<br class="">1. stored properties defined as part of enumeration type<br class="">enum RectSizes: MyRect<br class="">{<br class=""> &nbsp;&nbsp;&nbsp;let height:Int<br class=""> &nbsp;&nbsp;&nbsp;let width:Int<br class=""> &nbsp;&nbsp;&nbsp;case Small(width: 30, height: 30)<br class=""> &nbsp;&nbsp;&nbsp;case Medium(width: 60, height: 60)<br class=""> &nbsp;&nbsp;&nbsp;case Large(width: 120, height: 120)<br class="">}<br class=""><br class="">2. struct as rawValue<br class="">struct MyRect<br class="">{<br class=""> &nbsp;&nbsp;&nbsp;var height:Int<br class=""> &nbsp;&nbsp;&nbsp;var width:Int<br class=""> &nbsp;&nbsp;&nbsp;var area:Int {return height:Int*width}<br class="">}<br class=""><br class="">enum RectSizes: MyRect<br class="">{<br class=""> &nbsp;&nbsp;&nbsp;case Small(30,30)<br class=""> &nbsp;&nbsp;&nbsp;case Medium(60,60)<br class=""> &nbsp;&nbsp;&nbsp;case Large(120,120)<br class="">}<br class=""><br class="">3. tuples as rawValue<br class="">enum Format : (width:Int, height:Int) {<br class=""> &nbsp;&nbsp;&nbsp;case small(30, 30)<br class=""> &nbsp;&nbsp;&nbsp;case medium(60, 60)<br class=""> &nbsp;&nbsp;&nbsp;case large(120, 120)<br class=""><br class=""> &nbsp;&nbsp;&nbsp;var width:Int { return self.rawValue.width }<br class=""> &nbsp;&nbsp;&nbsp;var height:Int { return self.rawValue.height }<br class="">}<br class=""><br class="">Solutions 2 and 3 are quire similar, to get value of a stored property<br class="">we need to use rawValue or define value getters. In addition in<br class="">solution 2 we define an additional data type just to be used as an<br class="">enumeration type rawValue type. In my opinion, first approach would be<br class="">a best solution, type definition is clear and self-explanatory because<br class="">it is similar to how enums/classes are defined.<br class=""><br class=""><br class="">--<br class="">| Mateusz Malczak</div></div></blockquote><br class=""></div><div>Actually I'd say your option 2 here is more similar to option 1 (you seem to be using a struct to define the stored properties instead). The issue here is that storing properties conflicts with what you're actually doing, which is storing case-specific values, which is what rawValue already does, it's just too limited for your current use-case (multiple values).</div><div><br class=""></div><div>The complete solution would be to introduce the concept of tuples as literals (even though they can't currently conform to types); this would make it a lot easier to support the use of any type as a fixed value for each case (not just tuples). For example, say we introduced as new protocol:</div><div><br class=""></div><div><font face="Monaco" class="">protocol ExpressableByTuple {</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>associatedtype TupleType // somehow force this to be a tuple or ExpressableByType type</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init(tupleLiteral:TupleType)</font></div><div><font face="Monaco" class="">}</font></div><div><br class=""></div><div>With a bit of magic all tuples could conform to this protocol with themselves as the literal type, allowing us to use them as enum raw values; likewise this could then be used to more easily enable any custom struct/class for storage in enum cases, as instead of supporting their constructors directly we can just support construction via a tuple literal.</div><div><br class=""></div><div><br class=""></div><div>My other reason I don't favour option 1, while it looks a bit prettier, is that it's a bit confusing; enums have two types of stored properties, ones that can be changed (and inspected) which is what you get when you declare case small(Int, Int) for example, these are stored as part of the enum itself (so in that example it's 17-bytes on a 64-bit system). However rawValues are more like constants/static values, and don't increase the size of the type, and I just feel that this is the right way to do what you're proposing.</div></body></html>