func start() {
var num = 1
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
num += 1
}
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
print(num)
}
}
Running the method above prints 2, 3, 4, etc every second.
How does the second timer know about the current value of num
if it captures its own copy of num
? or does it throw num
into some sort of a reference type container and actually capture the pointer to num
? Let me know if the question is unclear.