Swift 3 WebView [英] Swift 3 WebView
问题描述
所以我刚刚更新到新的Xcode8
和Swift3
,但是现在我的Web视图不起作用.这是我使用的代码:
So I just updated to the new Xcode8
and Swift3
but now my web view does not work. Here is the code I used:
UIWebView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: "http://hardwirestudios.com")!))
现在给我这两个错误:
'NSURL'不能隐式转换为'URL';您是说要使用"as"进行显式转换吗?- "NSURLRequest"不能隐式转换为"URLRequest";您是要使用"as"进行显式转换吗?
'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?
推荐答案
在这种情况下,请重新输入以下行:
For this exact situation, retype your line to:
yourWebView.loadRequest(URLRequest(url: URL(string: "http://hardwirestudios.com")!))
...,然后将yourWebView
变量重命名为您实际使用的变量.
... and rename yourWebView
variable to one, that you actually use.
在Swift 3.0中,使用 URL 和 URLRequest ,因为几乎所有NS
都已删除.
In Swift 3.0, use URL and URLRequest as almost all the NS
were dropped.
这篇关于Swift 3 WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!