1

In our app, we make use of multiple NSManagedObjectContext instances, one per thread created. So when I'm about to use any object, I always make sure that I got the object from the correct context by doing this.

object = (ObjectClass *)[[contextProvider contextForCurrentThread] objectWithID:[user objectID]];

Since I want to make sure the object is updated I go and refresh it:

[[contextProvider contextForCurrentThread] refreshObject:object mergeChanges:YES];

And my question is: If I want to traverse relationships from this object, i.e object.someRelationship, Should I also make sure that the relationship is in the current context, and refresh it? What would be the correct approach?. Refetching and refreshing every time is such a pain...

4

1 回答 1

1
  1. 查看嵌套上下文和并发类型。它们不会解决您的根本问题,但它们比您已经拥有的要好得多。
  2. 你需要政策。在我看来,您的软件(根本不知道)似乎缺乏结构。结构伴随着政策。
  3. 即使您要一直刷新对象(所有对象),您也会遇到严重的竞争条件。

在不知道您的应用程序详细信息的情况下,除了“想想您的工作”和“介绍政策”之外,没有人可以提出任何建议。

于 2013-10-17T10:16:56.890 回答