NSFetchedResultsController错过合并的NSManagedObjectContext的更新 [英] NSFetchedResultsController misses updates on merged NSManagedObjectContext

查看:139
本文介绍了NSFetchedResultsController错过合并的NSManagedObjectContext的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个管理对象上下文A和B.这两个上下文保持同步,通过将更改从一个保存到另一个保存(通过监视 NSManagedObjectContextDidSaveNotification )。我已验证对A和B的更改正确合并。

I have two managed object contexts, A and B. These two contexts are kept in sync by merging changes from one to the other whenever they're saved (by monitoring NSManagedObjectContextDidSaveNotification). I've verified that changes to A and B are merging properly.

我有一个 NSFetchedResultsController 监视B的更新。我发现对A的某些更新不会导致nsfrc在B上创建一个新的管理对象并添加到A中,并使用nsfrc正在查找的属性(在B上),则在B合并A的保存更改之后触发nsfrc。但是,如果受管对象已经存在A(和B),并且我修改对象并保存A,同时我可以看到B正在合并来自A的保存通知的更改,nsfrc监视B不会触发。

I have an NSFetchedResultsController monitoring updates to B. I find that certain updates to A do not result in the nsfrc firing on B. When a new managed object is created and added to A with the attributes the nsfrc is looking for (on B), the nsfrc fires after B merges changes from the save of A. However, if the managed object already exists on A (and B), and I modify the object and save A, while I can see that B is merging the changes from the save notification of A, the nsfrc monitoring B does not fire.

我在这里缺少什么?

推荐答案

我有这个问题,似乎我已经解决了。我不知道我做了什么。我的意思是我做了几件事情,不知道,哪一个成为解决方案。所以我将简单描述...

I had this problem and it seems that I've solved it. I don't know what I did exactly. I mean I did a couple of things and don't know, which one became the solution. So I will simply describe...

我重构了我的代码以跟随一些提示,发现在官方文档&一些论坛:

I've refactored my code to follow some "hints", found in official docs & some forums:


  1. 如果你在另一个线程中管理 NSManagedObjectContext

  2. 您应该在主线程中添加observer(以获取合并的保存通知) - 这样它们也将合并到主线程中。
  3. (可选,但我做到了)你可以尝试在主线程中保存上下文,即使它是在后台线程中创建和管理的。



    1& 3看起来更像一些魔法,所以我想你应该尝试按照2先。希望这将帮助你。

1 & 3 looks more like some "magic", so I think you should try to follow 2 first. Hope this will help you.

这篇关于NSFetchedResultsController错过合并的NSManagedObjectContext的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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