【发布时间】:2013-05-03 16:08:32
【问题描述】:
这是在后台线程上。它是一个私有并发类型上下文,它在上下文 performBlock 中执行。我做得对,至少我认为是的。
我不是核心数据的初学者,但我可能会遗漏一些明显的东西 - 因为我已经盯着这个有一段时间了。
代码如下:
FFXCollection *backgroundCollection = (FFXCollection *) [context objectWithID:collectionID];
//At this point backgroundCollection.managedObjectContext is the same as context
NSError *error = nil;
[context save:&error];
NSLog(@"error %@", error); //Note that there is no error here
if (!backgroundCollection.managedObjectContext) {
DLog(@"why not?"); //At this point the managedObjectContext is nil!!!
}
为什么 managedObjectContext 在托管对象中变为 nil?
这个例子是人为的,但说明了我的问题。在我的实际代码中,发生了保存,然后我试图建立关系。然后当另一个保存发生时,由于上述原因,我得到了一个验证错误。
谢谢
【问题讨论】: