April 2026
Intermediate
683 pages
25h 29m
English
So far, you’ve learned that enumeration cases can hold attachments that are called associated values. In the preceding examples, those associated values were basic data types. Naturally, an associated value’s type can be another enumeration too.
Listing 7.28 demonstrates such an example. Severity is a simple enumeration, indicating a risk level. The following MessageType enumeration contains a case named error, which has an associated value of type Severity. In the main flow, the access to the associated type is also demonstrated.
// Enumerationsenum Severity { case low case medium case high}enum MessageType { case info case warning case error(severity: Severity)}// Main flowlet msgType1 = MessageType.infolet
Read now
Unlock full access