2014-05-24 1 views

답변

5

컨텍스트에서 생성 된 모든 개체는 임시 개체이며 해당 컨텍스트를 저장할 때 영구적으로 유지됩니다. 그래서 그들을 버리기 위해서, 당신은 단지 그 맥락을 저장하지 마십시오.

애플의 코어 데이터 스택 사용 가정 새로운 (임시) 컨텍스트를 만들려면, 당신은 다음 임시 상황에,이 세이브 하나를 수행하고 필요 주에 밀어 넣습니다

NSManagedObjectContext *tempChildContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; 
tempChildContext.parentContext = self.appDelegate.managedObjectContext; 

변경 사항을 저장하려면 문맥. 미안 해요

[tempChildContext performBlock:^{ 
    // do something that takes some time asynchronously using the temp context 

    // push to parent 
    NSError *error; 
    if (![tempChildContext save:&error]) 
    { 
     // handle error 
    } 

    // save parent to disk asynchronously 
    [self.appDelegate.managedObjectContext performBlock:^{ 
     NSError *error; 
     if (![self.appDelegate.managedObjectContext save:&error]) 
     { 
     // handle error 
     } 
    }]; 
}]; 

, 나는 MagicalRecord와 함께 할 방법을 기억하지 않지만, MR은 CoreData의 주위에 단지 래퍼입니다, 그래서 작동합니다. 내 첫 CoreData 프로젝트에서 MR 사용을 중단했습니다. 나는 이것을 읽을 것을 권합니다 : Multi-Context CoreData.

관련 문제