I don't want to use the reset method for my ManagedObjectContext. I only need to remove all of the objects for a specific entity, but I don't see any methods for doing this. Selecting all of the objects for a specific entity and looping over each and deleting them works, but it's very slow.
+3
A:
Selecting all of the objects for a specific entity and looping over each and deleting them works
That's pretty much how you do it.
Alex Reynolds
2010-04-30 20:28:51
That's it? Ridiculous. The reset method takes milliseconds versus this looping crap can take many seconds.
E-Madd
2010-04-30 20:33:08
If your entities have dependency relationships with other entities, those have to be managed. I'm pretty sure that's why they are called managed objects. There can be some overhead from this.
Alex Reynolds
2010-04-30 20:34:49
Wow. Nice attitude.
E-Madd
2010-04-30 20:49:36
I didn't mean any rudeness, just explaining why these objects are called "managed" — there's other stuff going on under the hood when you delete an object and save the context. If your deletions aren't running quickly, I'd recommend taking a look at the relationships in your data model, specifically looking at the delete rules for those relationships. If you "cascade" deletions, for example, there is overhead from these additional transactions. Hope this helps.
Alex Reynolds
2010-05-01 00:21:36