iOS ● ● ○ Swift 6

Kodebits Day 27: Optional Chaining

May 22 2026
Practice optionals with a short swift challenge.

What does this print?

let names: [String]? = ["Al"]
let count = names?.count
print(count ?? 0)
print(type(of: count))


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

1
Optional<Int>

Explanation:

Optional chaining on `names?.count` returns `Optional`, not `Int`. The nil-coalescing operator unwraps it for printing.

[/spoiler]


Further Reading