7
votes

I understand about NSObjectInaccessbileExceptions in general, and the need to avoid attempting to fault in an object that has been deleted in another managed context/thread.

However, in my user crash reports, I'm seeing an NSObjectInaccessibleException while merging/saving a child NSManagedObjectContext from a background thread (B) into my main context (A), which seems like an unusual scenario.

The only situation I can imagine that could cause such a thing is the following:

  1. change property of object in thread/context (B)
  2. delete object in thread/context A
  3. save context A
  4. save context B
  5. merge A into B and save A -> exception raised because object doesn't exist in A.

Has anybody else seen an exception in while saving the context like this? I tried to reproduce this manually, but failed. Is there some other scenario where this could happen, and are there any tips for dealing with such?

Thanks!

Fatal Exception
NSObjectInaccessibleException
CoreData could not fulfill a fault for '0x1f019da0 <x-coredata://741E65A8-C211-470E-8194-3005F0DFA71C/TrackInfo/p265>'
0   CoreFoundation  __exceptionPreprocess + 162
1   libobjc.A.dylib     objc_exception_throw + 30
2   CoreData    _PFFaultHandlerLookupRow + 1482
3   CoreData    -[NSFaultHandler fulfillFault:withContext:] + 24
4   CoreData    -[NSManagedObject(_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 236
5   CoreData    -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 96
6   CoreData    -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 918
7   CoreData    __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_0 + 564
8   libdispatch.dylib   _dispatch_barrier_sync_f_slow_invoke + 96
9   libdispatch.dylib   _dispatch_client_callout + 22
10  libdispatch.dylib   _dispatch_main_queue_callback_4CF + 228
11  CoreFoundation  __CFRunLoopRun + 1288
12  CoreFoundation  CFRunLoopRunSpecific + 356
13  CoreFoundation  CFRunLoopRunInMode + 104
14  GraphicsServices    GSEventRunModal + 74
15  UIKit   UIApplicationMain + 1120
16  app    main.m line 13    main
17  app    start 
1
Did you get any solution for this issue? - pradeepa
I would start by evaluating your use case for child contexts. Most of the time, they're used incorrectly, or for 'concurrency' which isn't really concurrent for IO. benedictcohen.co.uk/blog/archives/308 - Andy Riordan

1 Answers

0
votes

You may try using the following line while you are creating your child context:

privateManagedObjectContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy