Closure with explicit vs implicit capturing

Encountered the next code

var thing = "cars"

let closure1 = { [thing] in
print("I love (thing)")
}

let closure2 = {
print("I love (thing)")
}

thing = "airplanes"

closure1() // I love cars
closure2() // I love airplanes

Why is the behaviour different for explicit and implicit capturing ?

7 Likes

Turns out there is document that answers my question directly, thanks for pointing it out. Now it's clear!

1 Like