BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

DAY 14

Optionals


Null references – literally when a variable has no value – were invented by Tony Hoare way back in 1965. When asked about it in retrospect, he said “I call it my billion-dollar mistake” because they lead to so many problems.

This is the last day that you’ll be learning the fundamentals of Swift, and it’s devoted exclusively to Swift’s solution to null references, known as optionals. These are a really important language feature, but they can hurt your brain a little – don’t feel bad if you need to repeat some tutorials a few times.

In essence, an optional is trying to answer the question “what if our variable doesn’t have any sort of value at all?” Swift wants to make sure all our programs are as safe as possible, so it has some very specific – and very important! – techniques for handling this eventuality.

Today you have five tutorials to work through, where you’ll meet optionals, optional unwrapping, nil coalescing, and more. Once you’ve watched each video and optionally gone through the extra reading, there are short tests to help make sure you’ve understood what was taught.

Tip: Yes, there is optional reading about optionals, but these optionals aren’t empty!

  1. How to handle missing data with optionals
  2. How to unwrap optionals with guard
  3. How to unwrap optionals with nil coalescing
  4. How to handle multiple optionals using optional chaining
  5. How to handle function failure with optionals
  6. Summary: Optionals
  7. Checkpoint 9

Have some questions about optionals?

Hit Send below to start a virtual conversation with me.

How can this day be improved?

Great job on finishing another day! If you still have questions about what you learned, please send them in using this form – I'll do my best to address the most common problems in the next course update. Thank you!

Now share your progress…

If you use Twitter, the button below will prepare a tweet saying you completed today, along with a celebratory graphic, the URL to this page, and the challenge hashtag. Don't worry – it won't be sent until you confirm on Twitter!

Alternatively, copy and paste the text below to your preferred social network - I'm @twostraws on Mastodon.social, Bluesky, and Threads.

🎉 I just finished Day 14 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/swiftui/14 via @twostraws

Need help? Tweet me @twostraws!

 

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

100 Days of SwiftUI


The 100 Days of SwiftUI is a free collection of videos, tutorials, tests, and more to help you learn SwiftUI faster. Click here to learn more, or watch the video below.

Back to 100 Days of SwiftUI

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.