我的应用程序使用 Core Data(在 Magical Record 的帮助下)并且使用大量多线程NSOperation
.
当然我很小心只路过NSManagedObjectID
线程/操作之间。
现在,要返回操作中相应的托管对象,我使用-existingObjectWithID:error:
thus:
Collection *owner = (Collection *)[localContext existingObjectWithID:self.containerId error:&error];
但我得到的却是零error
说这是一个错误#13300:NSManagedObjectReferentialIntegrityError
.
以下是文档中关于此错误的说明:
NSManagedObjectReferentialIntegrityError
Error code to denote an attempt to fire a fault pointing to an object that does not exist.
The store is accessible, but the object corresponding to the fault cannot be found.
在我的例子中,这不是真的:该对象存在。事实上,如果我遍历所有实例Collection
实体具有NSFetchRequest
,我在其中找到了它,并且它NSManagedObjectID
正是我传递给的那个-existingObjectWithID:error:
.
此外,如果我使用-objectWithID:
相反,我得到了一个正确的对象就好了。
所以我缺少一些东西。以下是一些额外的观察/问题:
- “一个不存在的物体”:这句话中的“存在”是什么意思? “存在”在哪里?那时它肯定“存在”在我的核心数据存储中。
- “找不到与故障对应的对象”:这句话中的“找到”是什么意思? “发现”在哪里?那时它肯定会在我的核心数据存储中“找到”。
所以也许我错过了一些关于什么的事情existingObjectWithID:error:
做?文档说:
If there is a managed object with the given ID already registered in the context, that object is returned directly; otherwise the corresponding object is faulted into the context.
[...]
Unlike objectWithID:, this method never returns a fault.
这对我的问题没有帮助。我不介意让我的物品完全有缺陷,而不是有缺陷。事实上,当我访问对象属性时,其中的任何错误都会在下一个代码行中触发。
- 一个现实的场景会是什么?
NSManagedObjectReferentialIntegrityError
?
感谢您的任何启发。