[swift-evolution] Why does URL.checkResourceIsReachable() return a Bool?

Charles Srstka cocoadev at charlessoft.com
Sun Aug 7 14:14:38 CDT 2016


> On Aug 7, 2016, at 1:59 PM, Félix Cloutier <felixcca at yahoo.ca> wrote:
> 
> One line above the text that you quoted, you can read:
> 
>> If this method returns false, the object pointer referenced by error is populated with additional information.

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:

"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.”

> 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`.


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.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160807/724f4115/attachment.html>


More information about the swift-evolution mailing list