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

Félix Cloutier felixcca at yahoo.ca
Sun Aug 7 13:59:09 CDT 2016


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.

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

Félix

> Le 7 août 2016 à 10:41:32, Charles Srstka via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> -[NSURL checkResourceIsReachableAndReturnError:] has taken on several forms in Swift during its development, sometimes returning a Boolean and an error by reference, sometimes returning Void and using Swift’s do/try/catch system. In Swift 3, though, it appears to do both, which is weird:
> 
> func checkResourceIsReachable() throws -> Bool
> 
> All the documentation has to say about this is:
> 
> "This method is currently applicable only to URLs for file system resources. For other URL types, false is returned.”
> 
> It does not, however, say whether non-file URLs are the only thing that can cause a return of ‘false’, so I don’t know whether I should be checking the return value when checking a file URL or not. This results in having to check both the return value *and* the catch block each time, which is fairly awkward. I’m also not clear on why checking reachability on a non-file URL can’t just return an error like it did in the past.
> 
> What’s the rationale behind this?
> 
> Charles
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list