jonpeter jonpeter - 1 month ago 19
Swift Question

"Init(URL:)" has been renamed to "init(url:)" - swift 3 wkwebview error

First time using webkit alongside swift 3, and I keep getting this error regarding a web view load request. Why is Xcode announcing the renaming but maintaining the error?

var webView: WKWebView!
var websites = ["apple.com", "hackingwithswift.com"]

override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}

override func viewDidLoad() {
super.viewDidLoad()

let url = NSURL(string: "https://" + websites[0])!
webView.load(NSURLRequest(URL: url as URL) as URLRequest)
webView.allowsBackForwardNavigationGestures = true
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

Answer

As suggested by @LeoDabus, here's the code

class Controller: UIViewController {
    var webView: WKWebView!
    var websites = ["apple.com", "hackingwithswift.com"]

    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        let url = URL(string: "https://" + websites[0])!
        webView.load(URLRequest(url: url) as URLRequest)
        webView.allowsBackForwardNavigationGestures = true

    }
}