Join Harrison Ferrone for an in-depth discussion in this video Chaining optionals, part of Learning Swift 3 for Developers.
- [Harrison] Unwrapping one optional is all well and good…but in a real application,…you'll be dealing with multiple variables,…and unwrapping them one by one can be tiresome…and bloat your code base.…Let's look at how to chain unwrap multiple optionals.…Underneath our if let statement,…I'm going to make some room,…and add another header comment, Chaining Optionals.…Let's write out two new optional variables.…optional1 is going to be of type int optional,…and optional2 is going to be of type int optional.…
Let's start with an if let statement.…If let…optionalA equals optional1, curly braces,…and here we're going to add another embedded if let statement…inside the first one…so if let optionalB…equals optional2…and another curly bracket,…we're going to print out,…Both optionals are now unwrapped.…
Let's give these some values…so we actually see our print value.…Perfect.…So we've seen so far that Swift can provide…a lot of handy shorthand…for doing time-consuming operations.…Let's look at how we can unwrap multiple optionals…
- 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.