let _ = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { (timer) in
print("conunter \(counter += 1)")
}
conunter()
conunter()
conunter()
.........
但如果我這樣做
let _ = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { (timer) in
counter += 1
print("conunter \(counter)")
}
它產生預期的結果。爲什麼發生這種情況?
有點相關:[什麼是Swift賦值評估無效的原因?](https://stackoverflow.com/questions/34173084/what-was-the-reason-for-swift-assignment-evaluation-to-無效)。 –