我需要 Swift 中的多线程安全 Int
变量,它可以在不同的线程中递增或递减。此外,此变量必须每秒递减 1,并在其值为零时通知(通过 block 或选择器)。
实现它的最佳方法是什么?
最佳答案
关于apple swift block你不用考虑。
One of the primary reasons to choose value types over reference types is the ability to more easily reason about your code. If you always get a unique, copied instance, you can trust that no other part of your app is changing the data under the covers. This is especially helpful in multi-threaded environments where a different thread could alter your data out from under you. This can create nasty bugs that are extremely hard to debug.
https://developer.apple.com/swift/blog/?id=10
Int is a value type .因此,您可以放心地在多个线程中使用它。
关于ios - swift "timer"变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48403960/