<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">But that's an issue related to how serialising JSON works. Should the API serialise the name of the value and not the associated values, it should work fine. Should we have anything like annotations in Swift to describe how we wanted that output we'd have no problems.<br><br>About breaking things I wouldn't worry as Swift 3 is going to break a lot by itself anyway.<br><br></div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:janis.kirsteins@gmail.com">Jānis Kiršteins</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎25/‎05/‎2016 04:50 PM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:me@lmpessoa.com">Leonardo Pessoa</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [swift-evolution] [Proposal] Enums with static stored propertiesforeach case</span><br><br></div>That would replace current enum raw value functionality and I see two<br>problems with that.<br><br>1. A lot of breaking changes<br>2. Raw values currently are unique values among all cases. That makes<br>a possibility that enums can be easily serialized/deserialized to<br>formats like JSON, property lists, etc. In "case mercury = (mass:<br>3.303e+23, radius: 2.4397e6)" neither mass nor radius is unique value<br>(it is possible that two different planets could have the same mass as<br>radius).<br><br><br><br>On Wed, May 25, 2016 at 3:37 PM, Leonardo Pessoa &lt;me@lmpessoa.com&gt; wrote:<br>&gt; Hi,<br>&gt;<br>&gt; Couldn't this be solved by using tuples? If not because the syntax is not<br>&gt; allowed I think this would be more coherent to do it using current syntax.<br>&gt;<br>&gt; enum Planet : (mass: Float, radius: Float) {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case mercury = (mass: 3.303e+23, radius: 2.4397e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case venus = (mass: 4.869e+24, radius: 6.0518e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case earth = (mass: 5.976e+24, radius: 6.37814e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case mars = (mass: 6.421e+23, radius: 3.3972e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case jupiter = (mass: 1.9e+27, radius: 7.1492e7)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case saturn = (mass: 5.688e+26, radius: 6.0268e7)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case uranus = (mass: 8.686e+25, radius: 2.5559e7)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case neptune = (mass: 1.024e+26, radius: 2.4746e7)<br>&gt; }<br>&gt; ________________________________<br>&gt; From: Jānis Kiršteins via swift-evolution<br>&gt; Sent: ‎25/‎05/‎2016 08:58 AM<br>&gt; To: swift-evolution@swift.org<br>&gt; Subject: [swift-evolution] [Proposal] Enums with static stored properties<br>&gt; foreach case<br>&gt;<br>&gt; Hello everyone,<br>&gt;<br>&gt; Currently Swift only supports computed properties for each enum case.<br>&gt; If you want to somehow get static values with each case you would<br>&gt; probably do it like this:<br>&gt;<br>&gt; enum Planet {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case mercury<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case venus<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case earth<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case mars<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case jupiter<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case saturn<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case uranus<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case neptune<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; var mass: Float {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch self {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .mercury: return 3.303e+23<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .venus: return 4.869e+24<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .earth: return 5.976e+24<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .mars: return 6.421e+23<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .jupiter: return 1.9e+27<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .saturn: return 5.688e+26<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .uranus: return 8.686e+25<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .neptune: return 1.024e+26<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; var radius: Float {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch self {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .mercury: return 2.4397e6<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .venus: return 6.0518e6<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .earth: return 6.37814e6<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .mars: return 3.3972e6<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .jupiter: return 7.1492e7<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .saturn: return 6.0268e7<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .uranus: return 2.5559e7<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case .neptune: return 2.4746e7<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt; }<br>&gt;<br>&gt; However I see two problems with this approach:<br>&gt;<br>&gt; 1. These value definitions are spread out and difficult to read and<br>&gt; maintain (especially if you have many computed properties for each<br>&gt; enum case);<br>&gt; 2. These values are not static. They are computed each time property<br>&gt; is accessed. This can be a problem when value is expensive to create.<br>&gt;<br>&gt; The proposed solution is to have single static initializer for each<br>&gt; enum case that initializes stored properties. For example,<br>&gt;<br>&gt; enum Planet {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; var mass: Float<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; var radius: Float<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; static init(mass: Float, radius: Float) {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.mass = mass<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.radius = radius<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case mercury where (mass: 3.303e+23, radius: 2.4397e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case venus where (mass: 4.869e+24, radius: 6.0518e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case earth where (mass: 5.976e+24, radius: 6.37814e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case mars where (mass: 6.421e+23, radius: 3.3972e6)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case jupiter where (mass: 1.9e+27, radius: 7.1492e7)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case saturn where (mass: 5.688e+26, radius: 6.0268e7)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case uranus where (mass: 8.686e+25, radius: 2.5559e7)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; case neptune where (mass: 1.024e+26, radius: 2.4746e7)<br>&gt; }<br>&gt;<br>&gt; This approach do not affect enums that have raw or associated values,<br>&gt; or custom enum initializers:<br>&gt;<br>&gt; case A = "A" where (id: 0)<br>&gt;<br>&gt; or<br>&gt;<br>&gt; case B(Int, Int, Int) where (id: 0)<br>&gt;<br>&gt; Benefits:<br>&gt; 1. Less verbosity<br>&gt; 2. Improved readability<br>&gt; 3. Related values are closer to each other<br>&gt; 4. Static values are not recomputed<br>&gt; _______________________________________________<br>&gt; swift-evolution mailing list<br>&gt; swift-evolution@swift.org<br>&gt; https://lists.swift.org/mailman/listinfo/swift-evolution<br></body></html>