논리적으로 발생하지 않기 때문에 처리 방법을 이해할 수 없다는 문제가 있습니다.SEGV_ACCERR 및 충돌 응용 프로그램이 언젠가 NSOperation에 충돌 할 때 [self.managedObjectContext save : & error]
나는 동시에 실행되는 NSOperation
을 가지고 있습니다. 예를 들어,
- (void)main
{
@autoreleasepool
{
AppDelegate *appController = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = [[NSManagedObjectContext alloc] init];
[self.managedObjectContext setUndoManager:nil];
[self.managedObjectContext setPersistentStoreCoordinator: [appController persistentStoreCoordinator]];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(mergeChanges:)
name:NSManagedObjectContextDidSaveNotification
object:self.managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Entity" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"%K != %@",@"number1",[NSNumber numberWithInt:2]]];
NSError *error;
NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *obj in fetchedObjects) {
//Do Something with managed object then save
NSError *error = nil;
//[episode release];
if (![self.managedObjectContext save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate.
// You should not use this function in a shipping application, although it may be useful
// during development. If it is not possible to recover from the error, display an alert
// panel that instructs the user to quit the application by pressing the Home button.
//
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
}
- (void)mergeChanges:(NSNotification *)notification
{
AppDelegate *appController = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *mainContext = [appController managedObjectContext];
// Merge changes into the main context on the main thread
[mainContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)
withObject:notification
waitUntilDone:YES];
}
이없이 설명 응용 프로그램 충돌로 언젠가 동시에 작동하고 핵심 데이터에 내 개체를 업데이트하고, 그, 내 전형적인 NSOperation
내가이 라인에 해당 오류가 나타날 수
if (![self.managedObjectContext save:&error])
내 오류 보고서에서 내 질문에 앱 크래시를 방지하고 오류를 수정하는 방법이 있습니까? save
을 수행 할 때 @syncronized
을 사용할 수 있습니까? 이것은 다른 스레드와 다른 객체들 때문입니까? 이 문제를 어떻게 해결할 수 있습니까?
답장을 보내 주셔서 감사합니다. 그래서 저는 조엘처럼 슬픈 내 nsoperation을 변경할 필요가 없습니까? 내가했던 것처럼 main 메서드가 아닌 start 메서드를 재정의 하시겠습니까? – Piero
'NSOperationQueue'를 사용하면 필요 없습니다. @Piero는 [가져 오기 및 표시하는 대용량 데이터 세트 - 코어 데이터] (http://www.cimgf.com/2011/08/22/importing-and-displaying-large)도 살펴 봅니다. - 데이터 - 세트 - 코어 - 데이터 /). 이 경우에는 동시 작업 ('start' 메서드를 재정 의하여 구현)을 사용하는 것이 유용하지 않습니다. –
@ 피에로 당신에게 효과가 있습니까? –