<div dir="ltr">If you were to design this API for Swift in the first place, you might want to do something entirely different:<div><br></div><div>extension URL {</div><div> enum Reachability {</div><div> case reachable</div><div> case notReachable(ErrorProtocol)</div><div> }</div><div> func reachability() -> Reachability</div><div>}</div><div class="gmail_extra">
<br><div class="gmail_quote">On Sun, Aug 7, 2016 at 12:20 PM, Félix Cloutier <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I read it from the Mac Developer Library's documentation, which has all of that for the Swift version too (<a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/#//apple_ref/occ/instm/NSURL/checkResourceIsReachableAndReturnError:" target="_blank">link</a>).<div><br></div><div>I was commenting on the awkwardness of the Objective-C interface. Given that the error parameter is only populated when the return value is `false`, in the transposed Swift world, you shouldn't need to check the return value.<br><div>
<br><span style="color:rgb(0,0,0);font-family:'Lucida Grande';font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">Félix</span>
</div><div><div class="h5">
<br><div><blockquote type="cite"><div>Le 7 août 2016 à 12:14:38, Charles Srstka <<a href="mailto:cocoadev@charlessoft.com" target="_blank">cocoadev@charlessoft.com</a>> a écrit :</div><br><div><div style="word-wrap:break-word"><blockquote type="cite">On Aug 7, 2016, at 1:59 PM, Félix Cloutier <<a href="mailto:felixcca@yahoo.ca" target="_blank">felixcca@yahoo.ca</a>> wrote:<br></blockquote><div><blockquote type="cite"><br><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">One line above the text that you quoted, you can read:</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite">If this method returns false, the object pointer referenced by error is populated with additional information.</blockquote></div></div></blockquote><div><br></div><div>That’s only in the documentation for the original NSURL method (which still returns an error by reference). This is the entirety of the description in the documentation for the new one on URL:</div><div><br></div><div>"This method synchronously checks if the resource’s backing store is reachable. Checking reachability is appropriate when making decisions that do not require other immediate operations on the resource, e.g. periodic maintenance of UI state that depends on the existence of a specific document. When performing operations such as opening a file or copying resource properties, it is more efficient to simply try the operation and handle failures. This method is currently applicable only to URLs for file system resources. For other URL types, false is returned.”</div><br><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><div><div><span>The rationale is probably that this method was awkward to begin with. It's unclear to me why it was decided to return a `NSError` by reference and a bool that is seemingly equivalent to `error != nil`.</span></div></div></div></div></div></blockquote></div><div><br></div><div>It’s not like that anymore. On the new URL value type, it both returns a bool *and* is marked ‘throws’. So you have to check *both* whether it returned false *and* whether it threw an error.</div><br><div>Charles</div><div><br></div></div></div></blockquote></div><br></div></div></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>