この質問は以前に何度も尋ねられたように見えるかもしれませんが、答えを正しく集計したかどうかはわかりません。だからここに行きます。
ObjectIDは、Apple(WWDC 2012セッション214)によって、コンテキストセーフ、スレッドセーフとして記述されています。それで、それを利用するためにコードを変換するのに少し時間を費やしました。ただし、ここで説明するように、 コアデータ:子コンテキストが新しく挿入されたオブジェクトの永続的なobjectIDを取得することはありますか?そして他の場所では、パーマネントIDと呼ばれるものが存在します。
この永続的な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);
だから私は私のコードでこれに問題を抱えています。NSManagedObjectContextsの階層(たとえば、BとC)があり、そのうちの1つだけが実際に永続ストアにリンクされています(呼び出しはAです)。したがって、CはBの子であり、BはAの子です。CからNSManagedObjectを作成し、getpermanentIDsForObjectsを呼び出すと、実際には永続的ですか?.hファイルのコメントは、階層をB(エンティティをサポートする最初の書き込み可能なストアであり、子親の設定では、変更は1レベルだけ上にプッシュされます)までしか検索しないように読み取られるため、Aではありません。
前もって感謝します。