1
有谁知道如何在iOS 10中创建原子布尔值吗?Swift 3 - 原子布尔
当前代码:
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,以摆脱此警告?
谢谢!
问题的重点应该是如何让'atomic_fetch_or_explicit'工作。要做到这一点,你需要展示你的使用尝试,并说出失败的原因。 – Carcigenicate
比较https://stackoverflow.com/questions/39356873/swift-3-atomic-compare-exchange-strong。 - 编译器会警告不推荐使用的OSAtomic函数,但不会从''导入函数。 –