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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Final stage, final boss31s
-
(Locked)
Swift Enumerations2m 45s
-
(Locked)
Raw and associated values5m 53s
-
(Locked)
Introducing protocols5m 55s
-
(Locked)
Using extensions4m 31s
-
(Locked)
Throwing errors3m 18s
-
(Locked)
Handling errors7m 12s
-
(Locked)
Challenge: Battle actions39s
-
(Locked)
Solution: Battle actions4m 41s
-
(Locked)
-