NSManagedObjectContext和NSArrayController重置/刷新问题 [英] NSManagedObjectContext and NSArrayController reset/refresh problem

查看:106
本文介绍了NSManagedObjectContext和NSArrayController重置/刷新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将我的UI反映到sqlite数据存储的外部更改(由另一个进程创建)。

I'm having trouble getting my UI to reflect external changes (made by another process) to an sqlite data store.

我有一个相当标准的核心数据NSArrayController / table视图。我的应用程序得到通知,已对数据进行了外部更改,此时我做一个

I have a fairly standard core data based NSArrayController / table view. My app gets notified that external changes have been made to the data, at which point I do a

[managedObjectContext reset]; // brute force, but data set is small

问题是,这样做会清除表。数组控制器的arrangedObjects也是空的。我想以后的

The problem is, doing this clears all data from the table. The array controller's arrangedObjects is also empty. I thought a subsequent

[arrayController fetch:nil];

可能有帮助,但它没有。对managedObjectContext执行fetch请求会显示数据存在和更新,因此managedObjectContext知道更改。

might help, but it doesn't. Executing a fetch request on the managedObjectContext shows the data is present and updated, so the managedObjectContext knows about the changes.

有关如何从复位中恢复的任何线索?

Any clues as to how to "recover" from the reset? Or perhaps the reset approach is wrong altogether, in which case is there a better way to load the external changes?

推荐答案

我可以使用这种方法来加载外部更改不认为两个进程应该在同一个Core Data数据库中工作。最好让一个进程作为拥有(并打开)数据库的服务器,让其他进程发送命令来进行更改。我不认为Core Data曾经意在支持多个进程与同一个数据库通信。

I don't think two processes are supposed to work in the same Core Data database. It is probably better to let one process act as a server that owns (and opens) the database and let the other send it commands to make changes. I don't think Core Data was ever meant to support multiple processes talking to the same db.

这篇关于NSManagedObjectContext和NSArrayController重置/刷新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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