In this video, learn how to dramatically streamline code to handle optional values by using optional chaining syntax, and avoid the "pyramid of doom."
- [Instructor] Optional chaining makes it much easier…to access nested properties or subscripts,…and column methods of optional properties,…subscripts or methods.…I know that's a mouthful, an example will help.…But first, I'll review some setup code.…Don't be too concerned about the syntax here.…I'll cover all of it in due time throughout the course.…First, I've defined an employee class.…It has a name property of Type String…and a manager optional property of Type Employee.…In other words, an employee does not have to have a manager,…it can be nil.…
There's also an initializer…that lets me set the name property…when I create a new instance of employee.…And finally, employee has a print name function…that, well, prints the name.…Next, I've created several instances of employee:…Charlotte, Lori, Scott and Betty.…And then I've assigned Betty's manager to be Scott,…Scott's manager to be Lori,…and Lori's manager to be Charlotte.…This creates a hierarchy of employees and managers.…Because employees' manager property is an optional,…
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.