user1399797
user1399797

Reputation: 107

Core Data - How to disable faulting mechanism

Is there any way to tell Core Data to disable its memory management? I have NSManagedObjects in a view that don't get saved to a context for a very long time. The managed objects are in a table view. The user will see that view first, then navigate away to another view, spending lots of time there before returning to the table view. I am getting this exception: “NSObjectInaccessibleException - CoreData could not fulfill a fault”

Upvotes: 4

Views: 2520

Answers (2)

Dima
Dima

Reputation: 23634

To disable faulting when using an NSFetchRequest to get core data entities, just add the line [request setReturnsObjectsAsFaults:NO] before you execute the request.

Read more details here

Upvotes: 4

mprivat
mprivat

Reputation: 21902

A Core Data fault fulfillment error usually means that you are holding on to an object that has been faulted and another thread has deleted one of the children objects and committed to the persistent store. So when the original thread goes back to fulfill the fault, there isn't anything there anymore.

One of the things you can do is have your other views listen to NSManagedObjectContextDidSave and NSManagedObjectContextWillSave to react to the change as it is occurring (i.e. reload the data fresh), so you don't wind up with bad objects in the cache.

Upvotes: 1

Related Questions