#38: Autoclosures
Question
// Swift Quiz
— objc.io (@objcio) November 13, 2019
var result = 0
func update(_ completion: @autoclosure () -> (Int)) {
result = completion()
}
update(10)
// What’s the value of result?
Solution
Solution: 10
— objc.io (@objcio) November 15, 2019
When we call `update`, the 10 is automatically put in a closure. Because we then immediately evaluate the closure, `result` will have the value of 10.https://t.co/s7500CWmAg