I request a web page with this code
URLSession.shared.dataTask(with: NSURL(string: url)! as URL, completionHandler: { (data, response, error) -> Void in
if error == nil && data != nil {
// No error
}else{
// Error
if let httpResponse = response as? HTTPURLResponse {
print(httpResponse.statusCode)
}
}
I am trying to get the error code when requesting a page by casting the response to HTTPURLResponse
but the cast dose not work and the print is not executed. Do you know how can I get the code?