Stage 1 · Lesson 2 of 10
Optionals and unwrapping
An , written String?, either holds a value or holds nil, meaning nothing. will not let you use it as a String until you unwrap it, which means safely taking the value out. Learn the safe ways in order.
if let name { } gives you the value inside a block. guard let name else { return } leaves early when there is no value, which keeps the rest of the function flat. ?? gives a default.
Optional chaining, user?.address?.city, returns nil if any step is missing. lookups return optionals too.
Common trapthe force unwrap !, which crashes the app when the value is nil; keep it for values that are guaranteed, such as a built from a string literal you typed yourself.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with
- CourseFree100 Days of SwiftUI
Paul Hudson (Hacking with Swift) · Beginner
Days 1 to 15 teach Swift, with a checkpoint exercise every other day