April 2026
Intermediate
683 pages
25h 29m
English
The declaration of enumerations comes in multiple flavors. In this section, you will discover the options in that regard and we will evaluate the ideal use cases of each one.
Case enumeration values represent the most basic form. These are individual cases as type-safe identifiers. Listing 7.1 demonstrates the syntax to declare such an enumeration via the enum keyword.
enum Direction { case north case south case east case west}
Listing 7.1 Enumeration with Case Values
This code snippet should be mostly intuitive: enum Direction declares the enumeration named Direction, and each possible value is declared using the case keyword. As a shorter syntax option, Listing 7.2 demonstrates the same ...
Read now
Unlock full access