Skip to content

Instantly share code, notes, and snippets.

@messeb
Created December 5, 2017 21:00
Show Gist options
  • Save messeb/8bef6e9a1d0db2b5a881bd5a18ba392a to your computer and use it in GitHub Desktop.
Save messeb/8bef6e9a1d0db2b5a881bd5a18ba392a to your computer and use it in GitHub Desktop.
URLResponse as HTTPURLResponse and check if call has status code 2xx
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