penatheboss penatheboss - 3 months ago 95x
iOS Question

Type 'URL' has no member 'fileURL' - Swift 3

In Swift 2, I had used the following code:

let path = NSBundle.mainBundle().pathForResource("Document", ofType: "pdf")!
let url = NSURL.fileURLWithPath(path)
webView.loadRequest(NSURLRequest(URL: url))

Now, using Xcode 8 and Swift 3, Xcode automatically translated it to:

let path = Bundle.main.pathForResource("Translation", ofType: "pdf")!
let url = URL.fileURL(withPath: path)
webView.loadRequest(URLRequest(url: url))

On the second line, with the declaration of
, Xcode gives me the following error:

Type 'URL' has no member 'fileURL'

How can I fix this error? Thanks!


The URL struct in Swift 3 has an initializer for that

let url = URL(fileURLWithPath: path)