Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault

My iOS app uses core data via multiple threads. I am getting some crash reports with the following message: "'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x1e07a9b0 ''

I understand what is causing this problem - that the object was deleted but another thread is trying to access it. I am working to solve the problem but I want to add a check in the background thread to see if the object will fault in this manner.

My code at the moment relates to myObject.myValue. Is it possible to do some check, such as:

if (!myObject.myValue) {
    return;
}

... so that it will get out of the method before doing anything that could cause such a crash? Or will simply calling myObject.myValue, even to see if it's null, cause such an exception to be thrown?

like image 724
Jason Avatar asked Jan 12 '13 19:01

Jason


1 Answers

You could try and use existingObjectWithID:error::

Returns the object for the specified ID.

   - (NSManagedObject *)existingObjectWithID:(NSManagedObjectID *)objectID error:(NSError **)error

Discussion

If there is a managed object with the given ID already registered in the context, that object is returned directly; otherwise the corresponding object is faulted into the context.

This method might perform I/O if the data is uncached.

Unlike objectWithID:, this method never returns a fault.

You could dO:

if ([myMOC existingObjectWithID:myObject.objectID error:&error])
    ...
like image 164
sergio Avatar answered Sep 21 '22 14:09

sergio