O'Reilly logo

Mastering Swift by Jon Hoffman

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

Enumerations

Enumerations (or otherwise known as enum) are a special data type that enables us to group-related types together and use them in a type safe manner. For those of us who are familiar with enums from other languages, such as C or Java, enums in Swift are not tied to integer values. The actual value of an enum (known as the raw value) can be a String, a Character, an Integer or a Floating-point value. Enums also support features that are traditionally supported only by classes such as computed properties and instance methods. We will discuss these advanced features in depth in classes and structures chapter. In this section, we will look at the traditional enum features.

We will define an enum that contains the list of planets like this: ...

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