Join Harrison Ferrone for an in-depth discussion in this video The power of Swift enumerations, part of Learning Swift 3 for Developers.
- [Tutor] Swift enumerations are one of my favorite…all-purpose types in the Swift language…for the simple reason that they were written…to be able to do so much.…But before I get ahead of myself,…let's start with the basics.…I'm going to make some room underneath the Tuple section…and add a header comment…The Power of Swift Enums.…Declaring an enum is pretty simple.…You use the enum keyword and add a variable name.…Let's do an enumeration for PlayerState.…
I'm going to call this PlayerState underscore Basic.…After that, you need an open and close curly bracket.…To add enum cases, we can be super explicit…about declaring each one.…Let's declare three states,…case Alive, case KO and case Unknown.…If we want to go for the shorthand,…we can just use the case keyword once…and chain these together using commas.…With our enum as it is now,…we can access its hashvalue through dot notation.…
Let's make a new variable and call it basicState.…We're going to set it to PlayerState underscore Basic…and let's say Alive.…Now, for basicState, we can use dot hashvalue…
- Starting a new playground
- Printing to the console
- Declaring variables
- Working with numbers
- Using strings
- Breaking down optionals
- Understanding closures
- Classes vs. structs
- Extensions and protocols
Skill Level Beginner
1. Hello Swift
2. Back to Basics: Variables and Operators
3. Collections, Tuples, and Enumerations
4. Working with Logic Flows
5. Only in Swift: Optionals
6. Functions, Closures, and Associated Types
7. Classes vs. Structs
8. Advanced Topics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.