Ios 核心数据对象ID与永久对象ID

Ios 核心数据对象ID与永久对象ID,ios,objective-c,core-data,nsmanagedobjectcontext,objectid,Ios,Objective C,Core Data,Nsmanagedobjectcontext,Objectid,这个问题看起来好像以前被问过很多次,但我不确定我是否正确地汇总了答案。这就来了 Apple(WWDC 2012会话214)将ObjectID描述为上下文安全、线程安全。所以我花了一些时间转换我的代码来利用它。然而,它似乎不像他们所说的那样是上下文安全的,因为正如我们所讨论的和其他地方所讨论的,存在着一种叫做永久ID的东西 关于永久身份证业务,我查看了NSManagedObjectContext.h: /* Converts the object IDs of the specified obje

这个问题看起来好像以前被问过很多次,但我不确定我是否正确地汇总了答案。这就来了

Apple(WWDC 2012会话214)将ObjectID描述为上下文安全、线程安全。所以我花了一些时间转换我的代码来利用它。然而,它似乎不像他们所说的那样是上下文安全的,因为正如我们所讨论的和其他地方所讨论的,存在着一种叫做永久ID的东西

关于永久身份证业务,我查看了NSManagedObjectContext.h:

/* Converts the object IDs of the specified objects to permanent IDs.  This implementation
will convert the object ID of each managed object in the specified array to a permanent
ID.  Any object in the target array with a permanent ID will be ignored;  additionally,
any managed object in the array not already assigned to a store will be assigned, based on
the same rules Core Data uses for assignment during a save operation (first writable store
supporting the entity, and appropriate for the instance and its related items.)  Although
the object will have a permanent ID, it will still respond positively to -isInserted until
it is saved.  If an error is encountered obtaining an identifier, the return value will be
NO.
*/

- (BOOL)obtainPermanentIDsForObjects:(NSArray *)objects error:(NSError **)error NS_AVAILABLE(10_5, 3_0);
所以我在代码中遇到了这个问题。我有一个NSManagedObjectContext的层次结构(比如B和C),其中只有1个实际链接到持久存储(调用是a)。所以,C是B的子对象,B是A的子对象。如果我从C创建一个NSManagedObject,然后调用GetainPermanentsForObjects,它实际上是永久的吗?因为.h文件注释看起来像是只查找B层次结构(支持实体的第一个可写存储,在子-父设置中,更改只上推1级),而不是A


提前感谢。

是的,如果您调用
获取永久对象的ID
,那么您收到的ID应该是永久的(除非框架中存在任何实现错误,这在此时对于这个核心来说似乎不太可能)。

我得到一个“核心数据无法实现错误”获取子上下文中对象的永久id时。你有没有发现这是不允许的?