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?
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With