What does this print?
let numbers: [Int]? = [1, 2, 3]
print(numbers?.count ?? 0)
print(numbers?[1] ?? 0)
let empty: [Int]? = nil
print(empty?.count ?? 0)
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
3 2 0
Explanation:
Optional chaining returns nil if the optional is nil, then nil coalescing provides the default value
[/spoiler]