O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

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

Nesting and containing enumerations

Enums are so powerful in Swift that we can have enums, structs, computed properties, and methods in our enums.

We can logically nest an enum in another enum or struct and we can add additional information or context to our enum cases using computed properties, nested enums, or methods.

Let's look at an example:

struct NAAthlete {     enum Conference {         case eastern, western         static func conferenceFrom(division: String) -> Conference {             if division.contains("Metropolitan") ||                    division.contains("Atlantic") {                 return .eastern             } else {                 return .western             }         }     }     enum League {         case nhl         case mls         case nba         case mlb         enum Team {             case montreal             case anaheim             var conference: Conference {                 switch self {  case ...

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