Atomic
open class Atomic<T>
Atomic provides thread-safety to access a variable.
-
The thread-safe variable.
Declaration
Swift
open var value: T -
Init the
Atomicto access the variable in a thread-safe way.Declaration
Swift
public init(_ value: T)Parameters
valueThe variable needs to be thread-safe.
-
The provides a scheme to access and change the underlying variable in a block.
The variable can be accessed with
Box<T>.valueas:let atomic = Atomic([1,2,3]) atomic.withBox { array in array.value.append(4) return array.value.reduce(0, combine: +) }Declaration
Swift
open func withBox<U>(_ block: (Box<T>) -> (U)) -> UParameters
blockThe code to run with the variable wrapped in a
Box.Return Value
Any value returned by the block.
View on GitHub
Atomic Class Reference