Discover the enhanced capabilities of enumerations in Swift. See how to use enumerations to group related values. Get tips on how to write streamlined enumeration definitions.
- [Narrator] Enumerations play an important role in Swift,…more so than you might be used to seeing in other languages.…They enable grouping related values together…as a specific type of value.…Enumerations are also a value type,…so they're passed by copy.…The syntax to define an enumeration…is to write the enum keyword followed by the name…beginning with a capital letter…and using camel casing for multi-word names…and generally singular versus plural…even though they are used to group related values,…and then curly braces to enclose its body.…In the body, define one or more cases.…
These values should be written using camel casing…beginning with a lowercase letter.…This is a change from Swift 2…where enumeration cases conventionally began…with an uppercase letter.…To create an enumeration instance,…use dot notation to declare the enumeration type…and the specific member you want.…If the type can be inferred, you only need…to write the case using dot syntax.…
Multiple cases can be defined in one case statement…in a comma-separated list.…
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?
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.