views:

70

answers:

1

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
That's it? Ridiculous. The reset method takes milliseconds versus this looping crap can take many seconds.
E-Madd
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
Wow. Nice attitude.
E-Madd
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