How should I handle if there is an error occurs when there is no internet connection in Alamofire. I tried checking if data is nil or not but it does not work.
Below
Swift 5.0
You can check with NSURL-related Error Code
if error._code == NSURLErrorNotConnectedToInternet {
}
Or you can check with the code
if error._code == -1009 {
}
You can check other code on the developer site. https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes