Looking at the below code:
public override func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
if let urlError = error as? URLError {
switch urlError.code {
case .cancelled:
print("cancelled")
case .badURL:
print("badURL")
default:
break
}
}
}
The first question:
URLError
hasn't a property code
. It only has a public Struct Code
.
So why can use urlError.code
.
The second question:
URLError.Code
is a struct. It has many static property, the code likes below:
It isn't an enum. So why can use syntax case .cancelled:
.