Note that there are some explanatory texts on larger screens.

plurals
  1. POEXC_BAD_ACCESS when trying to access a managed object property
    primarykey
    data
    text
    <p>I'm having some trouble dealing with Core Data+concurrency/nested MOCs (not sure which one I'm having problems with =P).</p> <p>I have a method where I pass in a managed object ID (I checked that it's permanent) and that method has a child managed object context that is confined to a certain queue. I can retrieve the object from the child managed object context via <code>[managedObjectContext objectWithID:moID]</code> but when I try to access any of its properties (the managed object is still a fault), I get <code>EXC_BAD_ACCESS</code> with the stack trace showing <code>_svfk_1</code> and <code>objc_msgSend</code>.</p> <p>I know it's kind of difficult to figure out what the problem is without sample code, but I was hoping someone could shed some light on the possible causes. Thanks. =)</p> <p><strong>EDIT:</strong> I tried using <code>existingObjectWithID:error:</code> instead of <code>objectWithID:</code> as Tom Harrington suggested and now it works sometimes but doesn't work other times. I also experienced an <code>EXC_BAD_ACCESS</code> crash on <code>mergeChangesFromContextDidSaveNotification:</code>. I suspect this could be a synchronization issue. If I edit something in one context and save while something else is edited in my child context, would that cause an issue?</p> <p><strong>EDIT 2:</strong> I figured out why existingObjectWithID:error: was working sometimes but not always. The managed object ID was indeed a temporary ID (shouldn't <code>mergeChangesFromContextDidSaveNotification:</code> convert it to a permanent ID?), so I had to call <code>obtainPermanentIDsForObjects:error:</code> before passing the ID. But I'm still getting crashes sometimes in the child context's <code>mergeChangesFromContextDidSaveNotification:</code>. What could be the possible causes of this? Thanks.</p> <p><strong>EDIT 3:</strong> Here's what my MOC hierarchy looks like.</p> <pre><code> Persistent Store Coordinator | Persistent Store MOC / \ Main Queue MOC Child MOC (confinement) </code></pre> <p>I'm invoking a method from the main queue that uses the Child MOC (in another queue) to insert and update some managed objects and at the same time, I'm inserting and updating managed objects in the Persistent Store MOC. Managed objects can also be updated, deleted, and inserted in the Main Queue MOC at the same time. I merge any changes from the Persistent Store Coordinator to both the Main Queue MOC and the Child MOC.</p> <p>Some more questions: Does saving an MOC automatically merge things? If there is a pending merge request for an MOC and you save before that merge request is processed, can that cause issues?</p> <p><strong>EDIT 4:</strong> Here's how I initialize the Child MOC.</p> <pre><code>dispatch_sync(_searchQueue, ^{ _searchManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSConfinementConcurrencyType]; [_searchManagedObjectContext setParentContext:_persistentStoreManagedObjectContext]; [_searchManagedObjectContext setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy]; }); </code></pre> <p>Btw, I notice that the merge only crashes (with <code>EXC_BAD_ACCESS</code>) when the notification contains deleted objects.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload