iphone - Core Data executeFetchRequest throws NSGenericException (Collection was mutated while being enumerated) -


I am developing an iPhone app with core data All user data should be synchronized with our servers for this purpose For I created a sub-section of NSOption witch load from our web service and created related managed objects. To maintain the relationship between them, each object is transmitted with RemoteID (which is the primary key of the relational server DB).

Assume that there are two managed objects: Department & lt; - >> Employee. Synchronization works as follows:

  1. Load all departments from server for each department: Create a department object and set its remote ID.

  2. Load all employees from the server For each employee: Create an employee object, get the related department by Remotid and provide it to the employee.

The following exception is made by bringing a department:

*** Excluding 'NSGeral Expression' due to the exception of any exception, Reason: '*** Collection & lt; __nnsfsafeet: 0x69c8a10 & gt; Enumerated while mutating. & Lt; CFBasicHash 0x69c8a10 [0x2d6d380] & gt; {Type = mutable set, count = 1424, entries = & gt; & Lt; All newly created institutions & gt; A list of the first call on the throw stack: 0 core forwarding 0x02d04919 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x02e525de objc_exception_throw + 47 2 core forwarding 0x02d043d9 __NSFastEnumerationMutationHandler + 377 3 CoreData 0x026225d0 - [NSAMAdged object contact exchangeetheurequest: error:] + 4400 4 My app 0x00059 D4 + [Epiphichretari Department with RamoiteID: In-Manage Object Contact:] + 25 9

Every time an exception is not thrown, the problem is to move the code to the main thread. I do not know what is wrong. I have created a new NSManagedObjectContaxt in the synchronization thread and passed all object objects by its managed NSMANG object.

Any thoughts?

I had the same problem ... it was fixed because I managed object contexts Which was built on the main thread on the background thread. Its solution was to create a separate managed object contact on the background thread, and the regular Stustor Coordinator was used ... after that it worked fine!


Comments