Null Safety · 5.3
Optional Chaining
All lessons are open — jump whenever you need.
?. propagates nil without NPE:
struct Address { city: str? }
struct User { address: Address? }
let user = User { address: nil }
let city = user.address?.city ?? "Unknown"
print(city) // Unknown — no error!Goal: Create a User with nil address and get the city using optional chaining.
lesson-5-3.zolo
Program output
Run the code to see the output