Removing or Removing ManagedObject in CoreData

In the documentation and in the general literature, the generated factory method for removing / deleting a subclass of a managed object in CoreData for IOS

(void)removeXXXObject:(NSManagedObject *)value 

where XXX is the appropriate ratio, or we can use just removeObject.

In my code, I used this:

 Data *lastData = [[self sortedPersonDatas] objectAtIndex:0]; [selectedPerson removePersonDatasObject:lastData]; 

where PersonDatas is a one-to-many relationship with a data-driven object, from I took the last data (lastData obtained from a sorted array of all data) But using the first two methods of deleting and checking the SQL database behind, we can find that the actual data exist, only feedback is zero. To completely delete the data (all attributes and the object), I had to use:

 [selectedPerson.managedObjectContext deleteObject:lastData]; 

Question: which method is better, and does CoreData correctly leave the data intact?

+6
source share
1 answer

removeXXXObject removes only the object from the relationship to many, but does not remove the object from the repository. To do this, you really need to use deleteObject - this is the desired behavior. Calling deleteObject by default will also set the corresponding relationship to nil (see https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html#//apple_ref/doc/uid/ TP40001857-SW1 ).

+7
source

All Articles