As you have worked through the book up to this point, you have been using all the built-in types that Swift provides, like integers, strings, arrays, and dictionaries. The next couple of chapters will show the capabilities the language provides to create your own types. The focus of this chapter is enumerations (or enums), which allow you to create instances that are one of a predefined list of cases. If you have used enumerations in other languages, much of this chapter will be familiar. But Swift’s enums also have some advanced features that make them unique.
Create a new playground called Enumerations.playground. Define an enumeration of possible text alignments:
Listing 14.1 Defining ...