<div dir="ltr"><div><div>Currently, the syntax for explicitly naming property setters is:</div><div><br></div><div><font face="monospace, monospace">class Square {</font></div><div><font face="monospace, monospace"> var sideLength: Double = 0.0</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> var perimeter: Double {</font></div><div><font face="monospace, monospace"> get {</font></div><div><font face="monospace, monospace"> return sideLength * 4.0</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> set(newPerimeter) { // declares newPerimeter parameter, "let" not allowed</font></div><div><font face="monospace, monospace"> sideLength = newPerimeter / 4.0</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>Compare this with how extraction of associated values from enumerations looks:</div><div><br></div><div><font face="monospace, monospace">enum ServerResponse {</font></div><div><span style="font-family:monospace,monospace"> case Failure(String)</span><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> case Result(Int)</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace">let response = ServerResponse.Result(404)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">switch response {</font></div><div><font face="monospace, monospace">case .Failure(let reason): // let is required here</font></div><div><font face="monospace, monospace"> print(reason)</font></div><div><font face="monospace, monospace">case .Result(let code):</font></div><div><font face="monospace, monospace"> print(code)</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>For consistency, would it be better to allow/require:</div><div><br></div><div><div><font face="monospace, monospace">class Square {</font></div><div><font face="monospace, monospace"> var sideLength: Double = 0.0</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> var perimeter: Double {</font></div><div><span style="font-family:monospace,monospace"> get {</span></div><div><font face="monospace, monospace"> return sideLength * 4.0</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> set(<b>let</b> newPerimeter) { // declares newPerimeter parameter</font></div><div><font face="monospace, monospace"> sideLength = newPerimeter / 4.0</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>The idea would apply to didSet{} and willSet{} too.</div><div><br></div><div>-- <br></div><div class="gmail_signature">Ian Partridge<br></div>
<br>
</div>