views:

53

answers:

3

Hi guys, how can I remove all objects? I know I can remove one by

[managedObjectContext deleteObject:objToDelete];

is it possible to delete all without iterating all array? thanks

+2  A: 

Just iterate the array and delete them. There isn't a defined method for deleting them all.

Jesse Naugher
Ok, thank you, hope they will provide us with better way to do it in future:)
Burjua
+3  A: 

You can also just tear down the stack (releasing the NSManagedObjectContext, NSPersistentStore and NSManagedObjectModel) and delete the file. Probably would be faster than iterating over your entire database and deleting each object individually.

Also, it is unlikely they will provide this functionality in the future because it is easy to delete the file. However if you feel it is important then file a radar and let Apple know. Otherwise they won't know how many people want this feature.

Marcus S. Zarra
+2  A: 

Marking objects for deletion and then saving works the way it does because Core Data still needs to run the validation rules for all of the objects being deleted. After all, an object can refuse deletion based on how it responds to -validateForDelete:.

If:

  • you truly want to delete everything in a persistent store
  • and you don't care about whether the objects in that persistent store say they're valid for deletion

Then:

  • tear down the Core Data stack that's using that persistent store
  • and delete the persistent store's file.
Chris Hanson