O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Raw values

Enumeration members can come prepopulated with default values (called raw values), which are all the same type. The following example presents an incomplete HttpErrorenum with raw values:

enum HttpError: Int {     case badRequest = 400     case unauthorized = 401     case forbidden = 403 } 

In the preceding example, the raw values for enum called HttpError are defined to be of the Int type and are set to some of their integer code.

Raw values can be of String, Character, Int, or any floating number types. Each raw value must be unique within its enumeration declaration.

Raw values are set to prepopulated values when we first define the enumeration such as HttpError in the preceding example; therefore, the raw value for an enumeration case ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required