Basically, I'm trying to access some properties of a after deleting it from the NSManagedObjectContext
and saving the context. The problem is that, after saving the context, Core Data marks the object data as fault and, apparently, is unable to recover it.
I've created a sample project in order to replicate the issue, you can download it here. To illustrate, the following snippet:
City *city = [self.cities objectAtIndex:indexPath.row];
[self.managedObjectContext deleteObject:city];
if (![self.managedObjectContext save:&error]) {
[self.managedObjectContext rollback];
NSLog(@"Error: %@", error);
}else{
NSLog(@"%@", city);
// All properties of "city" are zeroed.
// Saved. Update data sources and animate changes...
}
produces:
<City: 0x7fe1cbd3cba0> (entity: City; id: 0xd000000000040004 <x-coredata://C1E3D3D8-188D-41DE-B701-08AF6D3E8860/City/p1> ; data: {
country = "0xd000000000080002 <x-coredata://C1E3D3D8-188D-41DE-B701-08AF6D3E8860/Country/p2>";
name = Rosario;
})
<City: 0x7fe1cbd3cba0> (entity: City; id: 0xd000000000040004 <x-coredata://C1E3D3D8-188D-41DE-B701-08AF6D3E8860/City/p1> ; data: <fault>)
The reason I'd like to access the managed object, after deleting it, is to update a NSMutableArray
which acts as data source for a table view and update another data source in a previous controller in the navigation controller stack (This is not implemented in the sample project).
Wrapping up, my questions are:
After deleting a NSManagedObject
from its NSManagedObjectContext
and saving the context, it is no longer guaranteed that the data in the managed object will be accessible? Even if a reference to that managed object is kept?
Based on what i've researched, Core Data is getting rid of the entity data to save memory once the context is saved. Is this assumption correct? Are there other factors that might be causing this data faulting?
Thanks.