Skip to content

Instantly share code, notes, and snippets.

@stormychel
Forked from messeb/URLResponse+HTTP.swift
Created May 9, 2024 04:33
Show Gist options
  • Save stormychel/01812be32d909e5f95f885ac4a889880 to your computer and use it in GitHub Desktop.
Save stormychel/01812be32d909e5f95f885ac4a889880 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