April 2017
Intermediate to advanced
316 pages
9h 33m
English
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 ...Read now
Unlock full access