iOS ● ○ ○ Swift 6

Kodebits Day 18: Optional Chaining

May 6 2026
Practice working with optionals in this short Swift challenge.

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]


Further Reading