2

I'm doing a bunch of core data inserts and after 20k or so inserts with saves every 1-2k I get this error:

Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <NSCFSet: 0x1b0b30> was mutated while being enumerated.'

I'm trying to figure out which NSSet is causing this. I've done a search and the only NSSets in my code are the autogenerated ones that handle the Core Data relationships.

I'm using NSXMLParser and for each element found creating a new entity (if a matching one doesn't already exist).

So I will create a state entity and then populate all the city entities and then do a save. This means that a state's NSSet *cities is getting added to but I don't see why you can't do that.

jamone
  • 17,253
  • 17
  • 63
  • 98
  • Are you doing this on a background thread? Is there perhaps any operation being performed on the entities on the main thread? Without a little code, it's going to be difficult to diagnose this, but in my limited experience, this exception occurs frequently when changing a set that is being iterated over, even if the operations are in separate threads. – warrenm May 02 '10 at 17:19
  • Yes this is on a background thread. My main thread is just showing an UIAlertView with a spinner/message. I will check to make sure that my underlying UITableViews aren't trying to refresh while the insert is going on though. – jamone May 02 '10 at 17:22

1 Answers1

8

Set a breakpoint on objc_exception_throw and grab a backtrace. That should indicate what is enumerating during mutation.

bbum
  • 162,346
  • 23
  • 271
  • 359