如何从Swift 3中的`Error`类型中获取`code`?

时间:2016-09-21 23:57:13

标签: swift swift2 swift3

我的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获取错误代码?

0 个答案:

没有答案