ThreadSpecificVariable
public final class ThreadSpecificVariable<Value> where Value : AnyObject
A ThreadSpecificVariable
is a variable that can be read and set like a normal variable except that it holds
different variables per thread.
ThreadSpecificVariable
is thread-safe so it can be used with multiple threads at the same time but the value
returned by currentValue
is defined per thread.
-
Initialize a new
ThreadSpecificVariable
without a current value (currentValue == nil
).Declaration
Swift
public init()
-
Initialize a new
ThreadSpecificVariable
withvalue
for the calling thread. After calling this, the calling thread will seecurrentValue == value
but on all other threadscurrentValue
will benil
until changed.Declaration
Swift
public convenience init(value: Value)
Parameters
value
The value to set for the calling thread.
-
The value for the current thread.
Declaration
Swift
public var currentValue: Value? { get set }