?. 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.
Run the code to see the output
9 results