Core Data on multiple threads

拜拜、爱过 提交于 2020-01-16 08:55:47

问题


I have a Core data managedObjectContext on the main thread, then I created another managedObjectContext on the background thread. If there is a change on the background thread I just call the ManagedObjectDidSave notification. My question is if I made a change on the mainthread, I also need to tell the managedObjectContext on the background thread right?

I have user a user data class which gets and sets userdata on both main and background thread. I should pass the managedobject of the thread I am calling this userdata class from, right?

Thanks for your help.


回答1:


My question is if I made a change on the mainthread, I also need to tell the managedObjectContext on the background thread right?

If you want to make the background thread aware of any changes on the main thread you must register it for notifications. Usually, however, the background thread has some special task to process and just ignores the main thread until it is done.

I have a user data class which gets and sets userdata on both the main and background threads. I should pass the managedobject of the thread I am calling this userdata class from, right?

Yes, keep the managedObject on the same thread until the context have merged.



来源:https://stackoverflow.com/questions/7166815/core-data-on-multiple-threads

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!