Created
December 5, 2017 21:00
-
-
Save messeb/8bef6e9a1d0db2b5a881bd5a18ba392a 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