如何强制NSArrayController重新加载MOC内容以反映最新的新鲜数据 [英] How to force NSArrayController to reload MOC contents to reflect latest fresh data

查看:218
本文介绍了如何强制NSArrayController重新加载MOC内容以反映最新的新鲜数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mac& iOS应用程序,使用iCloud CoreData之间来同步数据。

I am working on a Mac & iOS App, with iCloud CoreData in between to synchronize the data.

当我从iOS应用程序更新一些东西,更新已经迁移到Mac应用程序中的PersistentStore Mac应用程序正在运行。问题是我找不到一个有效的方法强制NSArrayController重新加载所有的数据从商店。

When I update some thing from iOS App, and the updates are already migrated to the PersistentStore in Mac App while the Mac App is running. The problem is I cannot find an effective way to force the NSArrayController to reload all data from the store.

试验 - (void)fetch:(id)sender;只能看到删除或添加的实体,但更新的模型属性不刷新...

tried -(void) fetch:(id)sender; only can see the delete or added entity, but the updated model property not refreshed...

请帮助。感谢

推荐答案

以下是Apple开发人员技术支持部门的回复。它为我工作。

Following is the reply from Apple's Developer Technical support. It worked for me. Thanks all for providing solutions.


对于OS X应用程序,当调用reloadFetchResults时,可以要求NSManagedObjectContext重置自己并执行fetch again。

For the OS X app, when reloadFetchResults is called, you can ask the NSManagedObjectContext to reset itself and perform the fetch again.



- (void)reloadFetchedResults:(NSNotification *)note
{
NSDictionary *userInfoDict = [note userInfo];

NSManagedObjectContext *moc = self.coreDataController.mainThreadContext;

// this only works if you used NSMainQueueConcurrencyType
// otherwise use a dispatch_async back to the main thread yourself
//
[moc performBlock:^{
    [self mergeiCloudChanges:userInfoDict forContext:moc];

    [moc reset];
    [self.tableArrayController fetch:self];
}];
}

这篇关于如何强制NSArrayController重新加载MOC内容以反映最新的新鲜数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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