9

이 질문은 전에 여러 번 묻는 것처럼 보일 수 있지만 답변을 올바르게 집계 한 것은 확실하지 않습니다. 그래서 여기에 간다.핵심 데이터 개체 ID 대 영구 개체 ID

개체 ID는 Apple (WWDC 2012 세션 214)에서 문맥 안전 스레드 안전하다고 설명합니다. 그래서 나는 그것을 활용하기 위해 코드를 변환하는데 시간을 보냈다. 그러나, 그것들이 소리를 내기 때문에 상황에 안전한 것으로 보이지는 않습니다. 왜냐하면 논의 된 것처럼 hereCore Data: Do child contexts ever get permanent objectIDs for newly inserted objects?과 다른 곳에서는 영구 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)의 계층 구조를 가지고 있고 그 중 단 하나만 실제로 영구 저장소 (호출은 A)에 연결되어 있습니다. 그래서, C는 B의 자식이고, B는 A.의 자식입니다. C에서 NSManagedObject를 만든 다음 obtainPermanentIDsForObjects를 호출하면 실제로 영구적입니까? .h 파일은 B에 대한 계층 구조 (엔터티를 지원하는 첫 번째 쓰기 가능한 저장소 및 자식 - 부모 설정) 만 조회하므로 읽지 못하기 때문에 A. 0이 아닌 1 단계로 변경됩니다.

감사합니다. 전진.

+0

자식 컨텍스트의 개체에 대한 영구 ID를 얻을 때 "핵심 데이터가 오류를 수행 할 수 없습니다."라는 메시지가 나타납니다. 이것이 허용되지 않는 것을 알았습니까? –

답변

2

예, obtainPermanentIDsForObjects으로 전화하면 수신 한 ID가 영구적 인 것으로 간주됩니다 (프레임 워크의 구현 버그가 없으며이 시점에서이 코어에 대해 별다른 문제가 없을 수 있습니다).