Search code examples
swiftoverloading

URL(filePath: strPath) vs URL(fileURLWithPath: strPath)


let url = URL(filePath: pathString!)
let url2 = URL(fileURLWithPath: pathString!)

I tried both and they worked both.

What's the difference between the two ways creating such an URL-object?


Solution

  • String file paths are outmoded. Use file URLs. And not file URLs derived from a string file path; construct or obtain the URL legitimately. So the real answer is: don't use either of those methods.