有人知道如何在 iOS 10 中制作原子布尔值吗?
当前代码:
import UIKit
struct AtomicBoolean {
fileprivate var val: UInt8 = 0
/// Sets the value, and returns the previous value.
/// The test/set is an atomic operation.
mutating func testAndSet(_ value: Bool) -> Bool {
if value {
return OSAtomicTestAndSet(0, &val)
} else {
return OSAtomicTestAndClear(0, &val)
}
}
/// Returns the current value of the boolean.
/// The value may change before this method returns.
func test() -> Bool {
return val != 0
}
}
代码按预期工作,但我不断收到警告:
'OSAtomicTestAndSet' was deprecated in iOS 10.0: Use atomic_fetch_or_explicit(memory_order_relaxed) from <stdatomic.h> instead
我无法让它与 atomic_fetch_or_explicit(memory_order_relaxed) 一起使用。
有谁知道如何将我当前的代码转换为 iOS 10,以消除此警告?
谢谢!