-
-
Save stormychel/01812be32d909e5f95f885ac4a889880 to your computer and use it in GitHub Desktop.
URLResponse as HTTPURLResponse and check if call has status code 2xx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URLResponse { | |
/// Returns casted `HTTPURLResponse` | |
var http: HTTPURLResponse? { | |
return self as? HTTPURLResponse | |
} | |
} | |
extension HTTPURLResponse { | |
/// Returns `true` if `statusCode` is in range 200...299. | |
/// Otherwise `false`. | |
var isSuccessful: Bool { | |
return 200 ... 299 ~= statusCode | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment