April 2017
Intermediate to advanced
316 pages
9h 33m
English
We have seen that enums in Swift are actually algebraic data types. Let's explore some examples to get more familiar with the topic.
The following example presents a simple enum NHLTeam with different options. Playing hockey is the second biggest sport after snow shoveling in Canada so don't get bored by the NHL examples!
The enum Team uses NHLTeam along with MLSTeam that we defined before to combine Hockey and Soccer teams. Team can be either a Hockey NHL team or a Soccer MLS team:
enum NHLTeam { case canadiens case senators case rangers case penguins case blackHawks case capitals } enum MLSTeam { case montreal case toronto case newYork case columbus case losAngeles case seattle } enum Team { case ...Read now
Unlock full access