Skip to content

Instantly share code, notes, and snippets.

@wmcbain
Created August 19, 2016 13:59
Show Gist options
  • Save wmcbain/8fd84094783e1660ae7dabb4140800ba to your computer and use it in GitHub Desktop.
Save wmcbain/8fd84094783e1660ae7dabb4140800ba to your computer and use it in GitHub Desktop.
extension NSHTTPURLResponse {
public enum HTTPStatus {
case info
case success
case redirect
case clientError
case serverError
public init?(_ rawValue: Int?) {
guard let statusCode = rawValue else { return nil }
switch statusCode {
case 100...199: self = .info
case 200...299: self = .success
case 300...399: self = .redirect
case 400...499: self = .clientError
case 500...599: self = .serverError
default: return nil
}
}
}
}
extension NSURLResponse {
public var httpStatus: NSHTTPURLResponse.HTTPStatus? {
return NSHTTPURLResponse.HTTPStatus((self as? NSHTTPURLResponse)?.statusCode)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment