7 Enumerations
Enumerations define a group of constant values in a type-safe way. They can include cases, associated values, and functions. Enums are powerful for modeling fixed sets of options, like directions.
Starting in this chapter, we will go through a series of Swift types that can hold data and functions simultaneously. Enumerations will be our first stop, which will be followed by structs and classes in the following two chapters.
We will start by offering a basic understanding of enumerations and follow that by examining their declaration syntax. You will see how to add computed properties and functions to enumerations and how to iterate over their values—similar to collections. We won’t finish the chapter before addressing recursion ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access