여러 요청을 비동기 적으로 실행하고 각 응답이 xml을 반환합니다. xml (나는 그것을 파싱하기 위해 TBXML을 사용하고있다)을 추출하여 핵심 데이터에 저장해야한다. UI가 너무 느려지므로 주 스레드에서이 작업을 수행 할 수 없습니다. 내가 뭘 각 XML 응답을 다음NSManagedObject에 대한 NSMergeConflict
dispatch_queue_t request_queue = dispatch_queue_create("com.queue.name", NULL);
dispatch_async(request_queue, ^{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *newMOC = [[NSManagedObjectContext alloc] init];
[newMOC setPersistentStoreCoordinator:[appDelegate persistentStoreCoordinator]];
newMOC setUndoManager:nil];
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify addObserver:self
selector:@selector(mergeChanges:)
name:NSManagedObjectContextDidSaveNotification
object:newMOC];
[self traverseElement:tbxml.rootXMLElement inMOC:newMOC];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:newMOC];
[newMOC release];
});
dispatch_release(request_queue);
- (void)mergeChanges:(NSNotification*)notification
{
AppDelegate *theDelegate = [[UIApplication sharedApplication] delegate];
[[theDelegate managedObjectContext] performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:notification
waitUntilDone:YES];
}는 traverseElement 방법에
, 나는 XML을 구문 분석하고 핵심 데이터에 데이터를 삽입합니다. 이 작업을 실행할 때 아래와 같은 병합 충돌이 많이 발생합니다. 어떤 아이디어가 왜이 문제를 디버깅하기위한 단서가 있습니까? 코어 데이터 모델을 변경하지 않았습니다.
NSMergeConflict for NSManagedObject with objectID '...'
with oldVersion = 117 and newVersion = 118 and
old object snapshot = ... and new cached row = ...
traverseElement가 수행하는 작업에 대한 간단한 설명을 제공 할 수 있습니까? – edsko