#28: @escaping
Question
// Swift Quiz
— objc.io (@objcio) August 28, 2019
var count = 0
class A {
var b: (() -> Void)?
func update(@escaping completion: () -> Void) {
b = completion
completion()
b?()
count += 1
}
}
A().update { count += 1 }
// What‘s the value of count?
Solution
Solution: Compiler Error
— objc.io (@objcio) August 29, 2019
The @escaping keyword is part of the closure's type, and should come after the colon, not before the name.https://t.co/s7500CWmAg