我的Swift 2.2项目中有一个webView。今天我将整个项目更新为Swift 3.除了从didFailLoadWithError
方法访问错误属性外,一切都进展顺利。
以下是我的error
:
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
print(error)
}
这是打印到控制台的内容:
Error Domain=NSURLErrorDomain Code=-999 "(null)" UserInfo={NSErrorFailingURLStringKey=https://test.com/, NSErrorFailingURLKey=https://test.com/}
在Swift 2.2中,我只是使用error.code
来获取-999
。 Swift 3向此Value of type 'Error' has no member 'code'
引发错误。
如何从error
获取错误代码?