Maybe this question requires a bit of context.
I\'ve been working on my persistence layer using Core Data and found out that Core Data isn\'t thread-safe and thus re
From The Swift Programming Language: Properties:
If a property marked with the
lazy
modifier is accessed by multiple threads simultaneously and the property has not yet been initialized, there is no guarantee that the property will be initialized only once.
lazy var
is not thread safe. You can use
dispatch_once
(runs once per lifetime of the app)let
)for thread safety. (See this question for some examples.)
You could also employ your own locking using NSRecursiveLock
but that's probably not as efficient as dispatch_once
.