What is the output?
var n = 5
let f = { print(n) }
n = 14
f()
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
14
Explanation:
Closures capture variables by reference by default.
[/spoiler]
var n = 5
let f = { print(n) }
n = 14
f()
Try it in the online Swift Playground →
[spoiler title="Solution"]
14
Closures capture variables by reference by default.
[/spoiler]