Look at the code and domain resulting NSError object. You can diagnose why he could not evaluate them.
For example, the domain NSURLErrorDomain and the code -1009 means that you are not connected to the Internet. So, in Swift 3:
if let error = error as? NSError, error.domain == NSURLErrorDomain && error.code == NSURLErrorNotConnectedToInternet { print("not connected") }
You can see a list of these codes in Global Variables - a reference to the Foundation constant . Just check out the NSURL Domain.
Also find NSURLErrorNotConnectedToInternet by pressing command + shift + o , and then you will be NSURLError.h to the corresponding header ( NSURLError.h ). Personally for this kind of thing, I tend to trust the headings a bit more than the documentation. If you perform this search when working with Objective-C, you will even see a cross reference to CFURLError codes (for which you can either click command or command + shift + o and look for kCFURLErrorNotConnectedToInternet ), and if you examine them, you will see numeric values โโassociated with these constants.
source share