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

Charles Srstka cocoadev at charlessoft.com
Sun Aug 7 12:41:32 CDT 2016

-[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?


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

More information about the swift-evolution mailing list