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]