Swift enum wrapper for easier handling of HTTP status codes.
The purpose of this library is to improve to clarify of code and remove the need for checking of status codes as numbers (==200
), or as a range of values (== 2xx
) - instead replacing it with descriptive enums.
All the RF2616 standard status codes are supported with a few added ones from the Wikipedia page.
With Cocoapods:
pod 'HTTPStatusCodes', '~> 1.0.0'
With Carthage:
github "rhodgkins/SwiftHTTPStatusCodes" ~> 1.0
In your source file:
import HTTPStatusCodes
Or drop HTTPStatusCodes.swift
into your project.
There are Bool
properties on the enum for checking if a status code is of a certain category:
isInformational
isSuccess
isRedirection
isClientError
isServerError
There is also an extension on NSHTTPURLResponse
to obtain a status code enum directly and to init
with one:
var statusCodeValue: HTTPStatusCode?
init?(URL url: NSURL, statusCode: HTTPStatusCode, HTTPVersion: String?, headerFields: [NSObject : AnyObject]?)