Reason:
This happens when the object’s context does not belong to the current thread. One of many ways that mistake can manifest itself.
Debug:
When the crash occurs do the following:
- Check the thread in which the crash occured (Xcode > Debug Navigator)
- On the console print, the concurrency type of the
NSManagedObjectContext - If the concurrency type is
mainQueueConcurrencyTypethen it needs to be on the main thread otherwise on the background threads.
Console command to check concurrency type:
p context.concurrencyType
In the sample command above the NSManagedObjectContext was stored in the variable context
Console Output:
(NSManagedObjectContextConcurrencyType) $R4 = mainQueueConcurrencyType