<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">One could associate `throws` with getter and setter, not with the subscript itself, e.g.<div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class="">subscript(index: Int) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>get throws {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>// ...</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>set {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>// ...</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class="">}</div></blockquote><div class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><font color="#929292" class=""><br class="Apple-interchange-newline">Pozdrawiam – Regards,</font></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><font color="#929292" class="">Adrian Kashivskyy</font></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Wiadomość napisana przez Jordan Rose via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; w dniu 07.12.2015, o godz. 20:59:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thanks for bringing this up, Nikolai. IMHO it does need a formal proposal because property (and subscript) access can be used in more interesting ways than just calling the getter or setter. In particular, how does this interact with inout? Is there a "rethrows" equivalent? What are the rules for overrides? (That last is probably very straightforward, but it ought to be written out explicitly.)</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 19:08, Nikolai Vazquez via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">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 class=""><br class=""></div><div class="">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 class=""><div class=""><div class=""><br class=""></div><div class=""><div class="">```swift</div><div class="">struct File&lt;Data&gt; {</div><div class="">&nbsp; &nbsp; var contents: Data {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; get throws { ... }</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; set throws { ... }</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class="">```</div></div></div><div class=""><br class=""></div><div class="">A better example would be getting and setting the current working directory of the process:</div><div class=""><br class=""></div><div class=""><div class="">```swift</div><div class="">import Foundation</div><div class=""><br class=""></div><div class="">extension Process {</div><div class="">&nbsp; &nbsp; static var workingDirectory: String {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; get {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let fileManager = NSFileManager.defaultManager()</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return fileManager.currentDirectoryPath</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; set throws {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let fileManager = NSFileManager.defaultManager()</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; guard fileManager.changeCurrentDirectoryPath(newValue) else {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw Error("...")</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">```</div></div><div class=""><br class=""></div><div class=""><br class=""></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZEz4qHYnXhPr3bBPu-2FxP4tN3HfWKL-2FtJpqkQ0gkOVSAlg6dL6D3u6hSuneuFUGyvunR-2FOIZKuXb9cfMbGfRXqJKrwq6-2B5PP0FfpFwR4PrXYRe3N-2BdKaAVlSb1xhNl3qNvW6Fl1QALXsuEOOR0EITBR-2BkLZf8urLlqlqnedYv-2BcpIXxabkLwoE4-2FhD1vIjulKHjMhcJeGshykGJQxnVQXV-2B3gjb4mFEGqZy2lx9dsiSk-3D" alt="" width="1" height="1" border="0" style="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;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Q0Y0L54uOhrrHtFzGFlMmzHCkni7p1uaN05dut7Y5S4Sz8V8qb4tt2w5M9p49fpfVx8-2BQ00IRq7bSso4TzlnNH3kvDT6OCRXegYDm8MnXUpmo69jQsNAwcYix3psjYv9uNGBqmyp029Tq-2FOkD8RdRZnKKQqoCjYlrHcbKeUyKkYSBhhsa3-2F369fBXzM5VdixPhO9nUwcxtqcFvfMMhLWly-2BR76Fbd2B-2F1iNw5Zb9PEc-3D" alt="" width="1" height="1" border="0" style="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;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>