クラッシュしました(おそらく親モックが保存されている間:
これがmocの作成方法です(親):
if (_managedObjectContextInMemoryForDynamicInformation) return _managedObjectContextInMemoryForDynamicInformation;
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinatorInMemoryForDynamicInformation];
if (!coordinator) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:@"Failed to initialize the store" forKey:NSLocalizedDescriptionKey];
[dict setValue:@"There was an error building up the data file." forKey:NSLocalizedFailureReasonErrorKey];
NSError *error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
[[NSApplication sharedApplication] presentError:error];
return nil;
}
_managedObjectContextInMemoryForDynamicInformation = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[_managedObjectContextInMemoryForDynamicInformation setPersistentStoreCoordinator:coordinator];
[_managedObjectContextInMemoryForDynamicInformation setUndoManager:nil];
return _managedObjectContextInMemoryForDynamicInformation;
子:
AppDelegate *delegateMain = (AppDelegate *)[[NSApplication sharedApplication] delegate];
_mocInMemoryForDynamicInformation = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[_mocInMemoryForDynamicInformation setUndoManager:nil];
_mocInMemoryForDynamicInformation.parentContext = delegateMain.managedObjectContextInMemoryForDynamicInformation;
これが私が保存する方法です:
-(void) finalSaveMocInMemoryForDynamicInformation;
{
[_mocInMemoryForDynamicInformation performBlock:^{
// do something that takes some time asynchronously using the temp context
// push to parent
NSError *error;
if ([_mocInMemoryForDynamicInformation save:&error])
{
AppDelegate *delegateMain = (AppDelegate *)[[NSApplication sharedApplication] delegate];
// save parent to disk asynchronously
[delegateMain.managedObjectContextInMemoryForDynamicInformation performBlock:^{
@try {
NSError *error;
if (![delegateMain.managedObjectContextInMemoryForDynamicInformation save:&error])
{
[self logError:error];
}
}
@catch (NSException *exception) {
NSLog(@"ERROR:%@:%@ exception->%@ inside managedObjectContextInMemoryForDynamicInformation",[self class], NSStringFromSelector(_cmd),exception);
//[[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:moc];
return ;
}
}];
} else [self logError:error];
}];
}
アプリケーション固有の情報: *キャッチされていない例外 'NSObjectInaccessibleException' が原因でアプリを終了しています。
Application Specific Backtrace 1: 0 CoreFoundation
0x00007fff86e6f0a6 __exceptionPreprocess + 198 1 libobjc.A.dylib
0x00007fff849353f0 objc_exception_throw + 43 2 CoreData
0x00007fff8737eec4 _PFFaultHandlerLookupRow + 1348 3 CoreData
0x00007fff8737e61f _PF_FulfillDeferredFault + 239 4 CoreData
0x00007fff873892cd _PF_ManagedObject_WillChangeValueForKeyIndex + 77 5 CoreData 0x00007fff8738cc51 _sharedIMPL_setvfk_core + 129 6 CoreData 0x00007fff873a4eaa -[ NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 1434 7 ファンデーション 0x00007fff878fe860 NSKeyValueNotifyObserver + 390 8 ファンデーション
0x00007fff87900279 NSKeyValueDidChange + 456 9 Foundation
0x00007fff878bb7df -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 130 10 CoreData
0x00007fff873898c1 -[NSManagedObject didChangeValueForKey:] + 113 11 CoreData 0x00007fff873e566d -[NSManagedObject(_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 685 12 CoreData 0x00007fff873b0969 -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 121 13 CoreData 0x00007fff873b0505 -[NSManagedObjectContext( _NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 629 14 CoreData 0x00007fff873df72a __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_0 + 634 15 libdispatch.dylib 0x00007fff8aad6a2d _dispatch_barrier_infokeslow 7 7.dylib 0x00007fff8aad10b6 _dispatch_client_callout + 8 17 libdispatch.dylib 0x00007fff8aad60c8 _dispatch_main_queue_callback_4CF + 275 18 CoreFoundation 0x00007fff86e110fe __CFRunLoopRun + 1614 19 CoreFoundation 0x00007fff86e106b2 CFRunLoopRunSpecific + 290 20 HIToolbox
0x00007fff89d950a4 RunCurrentEventLoopInMode + 209 21 HIToolbox
0x00007fff89d94e42 ReceiveNextEventCommon + 356 22 HIToolbox
0x00007fff89d94cd3 BlockUntilNextEventMatchingListInMode + 62 23 AppKit 0x00007fff8ffcd613 _DPSNextEvent + 685 24 AppKit 0x00007fff8ffcced2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128 25 AppKit 0x00007fff8ffc4283 -[NSApplication run] + 517 26 AppKit 0x00007fff8ff68cb6 NSApplicationMain + 869 27 コールfreecall
0x000000010e6ab472 メイン + 34 28 libdyld.dylib
0x00007fff858a47e1 スタート + 0 29 ???
0x0000000000000002 0x0 + 2