`lazy var` is not thread safe. You can use `dispatch_once`, a constant (`let`), or the nested struct pattern (typically used for singletons) for thread safety. You could also employ your own locking using `NSRecursiveLock` but that's probably not as efficient as `dispatch_once`.
It seems not all `lazy` variables are guaranteed to be initialized once in multi-threaded environment. You need to explicitly program it so or use static property.
> Although lazy loading may help developers to reduce memory footprint,
> to avoid loading too many data into the memory, or even to work around
> some sort of initialization or setup problems (such as setup views
> when you need to access self when the instance of self is not
> initialized). Nevertheless, applying lazy loading is not always
> toll-free: sometimes you will have to go extra miles to avoid
> side-effects. Lastly, don’t be afraid of lazy variables. it’s still a
> wonderful thing that can help you for the purpose of its existence.
> Cheers!
`lazy var` is not thread safe. You can use `dispatch_once`, a constant (`let`), or the nested struct pattern (typically used for singletons) for thread safety. You could also employ your own locking using `NSRecursiveLock` but that's probably not as efficient as `dispatch_once`.