Reputation: 1117
Can any one explain what coredata faulting means? I understood that it's a mechanism to reduce memory. But my question is, if when we try to use a faulted object, do we need to call any refresh methods or will CoreData picks the values for us? If CoreData handles it for us, what will happen if the faulted object is deleted from actual persistent store and we try to access it through faulted object? Will it throw any exception?
Upvotes: 15
Views: 11116
Reputation: 149
from Coredata reference (link):
Faulting reduces the amount of memory your application consumes. A fault is a placeholder object that represents a managed object that has not yet been fully realized, or a collection object that represents a relationship.
Upvotes: 3
Reputation: 51
Great answer from Dhruv! In answer to your final question, if you try to access a managed object which is first faulted then deleted, you will see an NSObjectInaccessibleException and the message "Core Data could not fulfill a fault"
Upvotes: 5
Reputation: 2775
In Core Data, faults are placeholders, or “unrealized objects”. They are small objects which refer to other NSManagedObjects, which are fetched into memory only as needed. This faulting mechanism is designed to enhance performance and reduce memory use.
In general, the faulting mechanism is transparent; when you retrieve an object from an NSManagedObjectContext (MOC) you can’t tell (in the normal course of its use) whether it’s a fault or a realized object. A fault will be converted into a realized object (“fired”) automatically by the Core Data framework in most cases when it is necessary to do so, e.g. when accessing a property of the object. If you need to fire a fault yourself, you can do so by invoking its willAccessValueForKey: method with a nil argument.
Upvotes: 34