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 url
, Xcode gives me the following error:
Type 'URL' has no member 'fileURL'
How can I fix this error? Thanks!
let url = NSURL(fileURLWithPath:path)
(although the class method seems to work), that's why the translation failed.