Atomic
A mutable thread safe variable.
@propertyWrapper
public class Atomic<T>
// Correct
atomicValue = 1
let value = atomicValue
atomicValue += 1 // Incorrect! Accessing and setting a value are two atomic operations.
_atomicValue.mutate { $0 += 1 } // Correct
_atomicValue { $0 += 1 } // Also possible
Initializers
init(wrappedValue:)
public init(wrappedValue: T)
Properties
wrappedValue
public var wrappedValue: T
Methods
mutate(_:)
Update the value safely.
public func mutate(_ changes: (_ value: inout T) -> Void)
Parameters
changes
: a block with changes. It should return a new value.
callAsFunction(_:)
Update the value safely.
public func callAsFunction(_ changes: (_ value: inout T) -> Void)
Parameters
changes
: a block with changes. It should return a new value.