Introduction
In Swift, an enumeration is a user-defined data type to group related values. An enumeration is a data type. Constants and variables can be declared using the data type defined by the enumeration.
An enumeration can be further supplemented with raw values and associated values that relate to that enumeration.
In this lesson, we learn how to define and use enumerations. We show how useful enumerations can be when writing Swift code.
Define an enumeration
In the following screenshot, we define a list of the schools available at our university:

The definition begins with the keyword enum, followed by the name of the enumeration. Because an enumeration is a data type (like Int, Double…), we also start this data type with a capital letter. The case keyword is used to define an enum value.
The name of an enumeration always begins with a capital letter.
The enumeration data type can be used to declare a constant or variable:

The constant school has data type UniversitySchool and is initialized with the value law. In the example we used the dot notation (.law) to refer to a value defined in the data type UniversitySchool instead of UniversitySchool.law.
Now school is an ordinary constant (data type UniversitySchool):

allCases
The allCases property generates an array of all cases available in the enumeration. The allCases property is available when you include CaseIterable in the enum definition:

The .map closure converts all enum cases into an Array of Strings.
Raw values
The cases in an enumeration can be supplemented with a default value of a specific data type. This data type applies to all cases. These additional values are called raw values :

The data type of all default values is defined as a String. The extra values can be accessed with the rawValue property. The schoolNames Array contains the default values (the official names of the schools) of all enum cases.
Associated values
With Swift, you can dynamically add extra data (so-called associated values) to specific enumerated values. With raw values, you could also add extra data of one specific data type for all enum cases. When using associated values, different additional values with their specific data type can be used for each enumerated case.

For all schools we want to keep track of the name of the dean (deanName: String). For the engineering school, on the other hand, we want to mention both the name of the dean (deanName: String) and the tuition fees (tuition: Double).
The engineering school can now be defined as follows:

The name of the dean (deanName) and the tuition fee (tuition) is dynamically added to the enumerated case engineering to define the engineeringSchool.
The switch statement can then be used to retrieve the additional data. The pattern (let deanName, let tuition) of the statement makes it possible to retrieve the associated values into local constants. This technique is called value binding.

A function within an enumeration
Functions can also be included in an enumeration. In the following example, we have included the getDeanName() function in the enumeration. The getDeanName() function must refer to the enumeration value passed during the call. This explains the use of the keyword self. The keyword self always refers to the actual value of the current object (instance).

The name of the dean of the school of medicine can be retrieved as follows:

In this case, UniversitySchool.medicine is the actual value that the switch self statement uses to determine the name of the dean.