开发者

Is singleton Thread Safe for Core Data?

I have a singleton class and I want to access it from multiple threa开发者_如何学Pythonds. The class return data from core data. I have two nsmanagedobjectcontext for each thread. Should I pass the nsmanagedobjectcontext to the singleton class from each thread?


It's safe to access Core Data from different managed object contexts in different threads. You should pass the managed object context to your singleton somehow. Whether your own code in your singleton class is thread safe is up to you.

Another option would be to use one managed object context for all the threads, but lock the persistent store before accessing any Core Data properties. Multiple managed object contexts is preferable, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜