(no title)
GRiMe2D | 1 year ago
var count = 0
let closure = {
count += 1
print("Current count=", count)
}
closure() // Current count= 1
closure() // Current count= 2
closure() // Current count= 3
let capturedVariableClosure = { [count] in
print("Current count=", count)
//count += 1 // syntax error, count is const variable. Use var count in capture group
}
capturedVariableCount() // Current count= 3
closure() // Current count= 4
capturedVariableCount() // Current count= 3
jb1991|1 year ago