iOS ● ● ● Swift 6

Kodebits Day 25: Capture List Value

May 18 2026
Practice closures with a short swift challenge.

What does this print?

var n = 3
let f = { [n] in n + 2 }
n = 14
print(f())


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

5

Explanation:

The capture list `[n]` captures `n`’s value (3) at closure creation time. Changing `n` to 14 afterward doesn’t affect the closure, so `f()` returns 5.

[/spoiler]


Further Reading