#40: Closures and Variable Capture
Question
// Swift Quiz
— objc.io (@objcio) December 18, 2019
var language = "Objc"
let code = { [language] in
print(language)
}
language = "Swift"
let newCode = code
newCode()
// What's the output?
Solution
Solution: Objc
— objc.io (@objcio) December 19, 2019
The moment the closure is created (when we define `code`) the `language` variable is captured: the value at that point in time is available within the closure's body.https://t.co/s7500CWmAg