Learn how to associate additional values of any type to enumeration cases, include labels to improve readability, and use switch statements to access and work with associated values.
- [Narrator] Enumeration cases can also…associate values to them of any type.…However, an enumeration can either be of a raw value type…or associate data, not both.…Perhaps the simplest example of enumerations that…associate values is optionals.…Behind the scenes, optionals are…implemented as a enumeration.…Either an optional has some value,…which is associated to the case by writing it in…parenthesis after the value name,…or it is empty, which is represented by the .none case.…
And also notice, that an enumeration can mix cases…that associate values with regular cases that do not.…For slightly more elaborate example,…let's say I'm developing an app,…that searches iTunes.…I need to create URLs that include user entered info…such as what kind of media they're searching for,…and their search term.…I'll start off by creating a base URL string…and an enumeration with a raw value type of string,…to model media entity types.…There are several types,…but I'll just include a couple here to keep things simple.…
Now I'll define an end point enumeration.…
Learn how to write code, understand Swift's key concepts and best practices, and strengthen your programming problem-solving skills. Instructor Scott Gardner teaches the fundamentals, so you'll be prepared to develop applications for iOS, macOS, and other platforms. Completing this course will enable you to not only write first-class code, but to think like a Swift developer.
- Creating playgrounds
- Defining variables and constants
- Working with characters and strings
- Working with collections and groups
- Using operators and defining custom operators
- Controlling program flow
- Defining functions and closures
- Working with classes, structures, and enumerations
- Adopting protocols
Skill Level Beginner
1. Get Started
2. Variables and Constants
3. Characters and Strings
4. Collections and Tuples
6. Control Flow
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
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.