Its_ToXiiC Its_ToXiiC - 2 months ago 164
Swift Question

Swift 3 WebView

So I just updated to the new Xcode 8 and Swift 3 but now my web view does not work. Here is the code I used:

UIWebView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: "http://hardwirestudios.com")!))


Now gives me these two error:


'NSURL' is not implicitly convertible to 'URL'; did you mean to use 'as' to explicitly convert?


-


'NSURLRequest' is not implicitly convertible to 'URLRequest'; did you mean to use 'as' to explicitly convert?

Answer

For this exact situation, retype your line to:

youWebView.loadRequest(URLRequest(url: URL(string: "http://hardwirestudios.com")!))

... and rename yourWebView variable to one, that you actually use.

In Swift 3.0, use URL and URLRequest.

Comments