<div dir="ltr">+1<br></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 5, 2015 at 10:17 PM Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">+1 to this.  Subscripts should also be able to throw and currently cannot.</div><div style="word-wrap:break-word"><div><br></div><div><br><div><blockquote type="cite"><div>On Dec 5, 2015, at 9:08 PM, Nikolai Vazquez via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr"><div>One of the aspects of Swift that I like is computed properties for structures and classes. It allows for adding logic when obtaining values or for having the returned value be dependent on another.</div><div><br></div><div>As of the `ErrorType` protocol introduction in Swift 2, we can throw errors when it comes to functions and initializers. However, this does not apply to getters and setters.</div><div><div><div><br></div><div><div>```swift</div><div>struct File&lt;Data&gt; {</div><div>    var contents: Data {</div><div>        get throws { ... }</div><div>        set throws { ... }</div><div>    }</div><div>}</div><div>```</div></div></div><div><br></div><div>A better example would be getting and setting the current working directory of the process:</div><div><br></div><div><div>```swift</div><div>import Foundation</div><div><br></div><div>extension Process {</div><div>    static var workingDirectory: String {</div><div>        get {</div><div>            let fileManager = NSFileManager.defaultManager()</div><div>            return fileManager.currentDirectoryPath</div><div>        }</div><div>        set throws {</div><div>            let fileManager = NSFileManager.defaultManager()</div><div>            guard fileManager.changeCurrentDirectoryPath(newValue) else {</div><div>                throw Error(&quot;...&quot;)</div><div>            }</div><div>        }</div><div>    }</div><div>}</div><div><br></div><div><br></div><div><br></div><div>```</div></div><div><br></div><div><br></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAfl-2BiqO0EPyHMi667csqGqnS8zsvC7hbTRcL7iqVxqOu9cb5ugMs9I3ip1C1qB2VCU4zyE0-2BusyW7-2B5YjqXTkIOPkyK7hYPEZWwLg1cnt-2BMhGFgwqbARFu1Sb3jUC6K6X5teb8G88uQTbm25lS3XU6ssgzLoO3vj6xmHfA-2BITsySoiYEEpwkTjJ5WUTCC9C5cE-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JoVvr1nwtkf-2FcycRIsh0Ekp6hrdbCH7iUjVG-2FENQSuc5ZTgbmoiSS5unkMWZibz5QPhtASRyZABuuxU3qAUa211tuOyIfNND-2BgQwAAqfYnv7Tl1-2FIL2HKdCjtBKWW2xHMAZmZ4s4f1NQeJ4fUj2fbR-2Fi-2FvhMY2cQ3CEMreDiffC7-2FfZRo5nbkClRbRAKl3NtFFjiMTH2k3Q6GIiHbp4FFT2Uek3EdvDJSly5Jp3mouk-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>