Skip to content

MadsBogeskov/SwiftHTTPStatusCodes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftHTTPStatusCodes

Build Status Pod Version Pod Platform Pod License Carthage compatible

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.

Usage

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.

Helper methods

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]?)

About

Swift enum wrapper for easier handling of HTTP status codes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 90.7%
  • Ruby 5.5%
  • C++ 3.8%