CoreData asynchronous fetch causes concurrency debugger error
I think this is Apple's bug.
I filed bug report:https://openradar.appspot.com/30692722
and added example project that reproduces issue:https://github.com/jcavar/examples/tree/master/TestAsyncFetchCoreData
Also, if you don't want to disable flag just because of this issue you may want to swizzle __Multithreading_Violation_AllThatIsLeftToUsIsHonor__
method on NSManagedObjectContext
just for this part of code.You need to revert that after request is executed so you get violations for real issues.
The concurrency debugger is telling you that you are accessing MOC
from the wrong thread/queue. You can only call -executeRequest: error:
on the thread/queue that the context belongs to. If this is a NSMainQueueConcurrencyType
then you need to be on the main thread. Otherwise, if it is a NSPrivateQueueConcurrencyType
you need to use either -performBlock:
or -performBlockAndWait:
to run the execute on the correct queue.
I added a screenshot, see above. The request is enqueued from the main thread, but executed on another.
Ok, a couple of things:
- Is that the line that is breaking/crashing or are you seeing the error output?
- Your error handling is incorrect. You should be looking at the result of the
-executeRequest: error:
and if the result isnil
then you are in an error state. The error variable can be populated even with a success.
I note that the code you posted in your screenshot is different than the code you posted previously. Did you add the -performBlock:
or just not include it originally?