Chapter 17
Working with Enumerations to Consolidate Values
In This Chapter
Using raw values with enumerations
Combining enumerations with switches
Adding functions to enumerations
Swift takes structures and enumerations far beyond their roots in C and C-like languages. Structure, classes, and enumerations all can contain functions as well as data elements. They also can all adopt protocols.
This chapter shows you how to use Swift enumerations both in traditional ways and in ways that work alongside new Swift features such as embedded functions and raw values.
Using Enumerations with Swift
In the world of Swift, you may want to rethink how you use enumerations.
Whereas in C, structures and enumerations are often used as simple types (that is, more or less as a way of saving keystrokes or organizing the code), structures, enumerations, and classes in Swift are all object-oriented first-class types. Accordingly, then, in the world of Swift, it is common to refer to instances of structures and enumerations, as well as instances ...
Get Swift For Dummies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.