Advanced and Practical Enum usage in Swift

Status Codes

released Fri, 01 Mar 2019
Swift Version 5.0

Status Codes

If you're working with an outside system which uses status codes (or error codes) to convey information, like HTTP Status Codes, enums are obviously a great way to encode the information. 1

enum HttpError: String {

   case code400 = \"Bad Request\"

   case code401 = \"Unauthorized\"

   case code402 = \"Payment Required\"

   case code403 = \"Forbidden\"

   case code404 = \"Not Found\"

}