In Java, we have a ThreadLocal class:
This class provides local stream variables. These variables differ from their usual counterparts in that each thread that accesses it (through its get or set method) has its own, independently initialized copy of the variable. ThreadLocal instances are typically private static fields in classes that want to associate state with a thread (for example, user ID or transaction ID).
Example:
private static final ThreadLocal<StringBuilderHelper> threadLocalStringBuilderHelper = new ThreadLocal<StringBuilderHelper>() { @Override protected StringBuilderHelper initialValue() { return new StringBuilderHelper(); } };
Is there any equivalent in Objective-C or Swift to simulate this behavior? Can I just use in Swift:
static let String = someInitialValue()
and achieve the same goal?
source share