Contents

rhodgkins/swifthttpstatuscodes

Swift enum wrapper for easier handling of HTTP status codes.

Usage

Swift versions support

  • Swift 5.1 - use version 3.3.2
  • Swift 5 - use version 3.3.1
  • Swift 4 - use version 3.3.0
  • Swift 3 - use version 3.1
  • Older versions - use version 3.0

Swift Package Manager

Add this package to the dependencies in your Package.swift file:

.package(url: "https://github.com/rhodgkins/SwiftHTTPStatusCodes.git", .upToNextMajor(from: "3.0.0"))

Carthage

Cartfile:

github "rhodgkins/SwiftHTTPStatusCodes" ~> 3.3

Source code:

import HTTPStatusCodes

CocoaPods

Podfile:

pod 'HTTPStatusCodes', '~> 3.3.0'

Source code:

import HTTPStatusCodes

Manually

Or drop in the Swift files inside the Sources folder 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 HTTPURLResponse to obtain a status code enum directly and to init with one:

var statusCodeValue: HTTPStatusCode?
init?(url: URL, statusCode: HTTPStatusCode, httpVersion: String?, headerFields: [String : String]?)

Package Metadata

Repository: rhodgkins/swifthttpstatuscodes

Default branch: master

README: README.md