多线程上的核心数据 [英] Core Data on multiple threads

查看:57
本文介绍了多线程上的核心数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主线程上有一个核心数据managedObjectContext,然后在后台线程上创建了另一个managedObjectContext.如果后台线程有变化,我只需调用ManagedObjectDidSave通知.我的问题是,如果我在主线程上进行了更改,还需要告诉后台线程上的ManagedObjectContext对吗?

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?

我为用户提供了一个用户数据类,该数据类在主线程和后台线程上获取并设置userdata.我应该传递我从中调用此userdata类的线程的托管对象,对吧?

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?

感谢您的帮助.

推荐答案

我的问题是,如果我对主线程进行了更改,我还需要告诉背景线程上的managedObjectContext对吗?

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.

我有一个用户数据类,它在两个主数据块上获取并设置用户数据和背景线程.我应该传递线程的托管对象我从这里调用这个userdata类,对吧?

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?

是的,将ManagedObject保留在同一线程上,直到上下文合并为止.

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

这篇关于多线程上的核心数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆