What is the output?
struct User {
var name: String
}
var user: User? = nil
print(user?.name ?? "Guest")
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
Guest
Explanation:
Optional chaining (?.) returns nil when the optional is nil. The nil-coalescing operator (??) provides a default value.
[/spoiler]