From the course: Swift 6 Essential Training

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Raw and associated values

Raw and associated values - Swift Tutorial

From the course: Swift 6 Essential Training

Raw and associated values

- [Instructor] Enumerations can be expanded to include raw values of sequential or unique values or associated values which capture case specific parameters. Let's declare a new enum here. I'm going to call this non playable characters. We're going to have three cases here, a villager, a blacksmith, and a merchant. And we can specify a raw value type by adding a colon after the enum name. And we want this to be a string type, so we'll just add the string class. Swift is going to take care of setting string and integer raw values for us by default. So if we create a new NPC, we'll just say VAR blacksmith equals non playable characters blacksmith. Now, if we print out the raw value of blacksmith, we'll just get it string representation. If we change our raw value type to an integer, we can see that blacksmith is going to be an integer of one, or raw value of one. Since Enums, like everything else we've seen, are zero…

Contents