Enumerations (aka enums) are found in most programming languages as a means to
associate a symbol with set membership over a closed group of alternatives. In
some cases, the values associated with an enum are meaningless (e.g.
Male, Female) and in other cases they hold useful
data (e.g. East might have a value of 90 and
NorthEast might have a value of 45).
Traditional languages represented an enumeration always as an alias for an
integral value and used sleight-of-hand to replace the value at compile time,
like a set of #define constants. Although this worked, it meant
that enums could be substituted for one another even when it didn’t make sense
(e.g. Male == North).
Swift’s enums are more powerful, and enum types are distinct, even if they
represent the same values. As a result, it is not possible to compare two
enums for equality unless they are of the same type.
For example, to create a simple enum for representing gender:
There’s no comparison or ordering between different elements; they are just
a property which can be one or the other. The enumeration type can be used
as an argument type, return type, or variable type using a dot syntax as