Fixing Core Data Concurrency Violations
With iOS 8.0 Apple gave us access to a tool for tracking down code that violates Core Data concurrency rules. This post outlines how to setup Xcode so that you can identify and fix the faulty code.
According to the Core Data concurrency rule, each thread must have its own managed object context. This is because NSManagedObjectContext and NSManagedObject, two most fundamental objects in Core Data, are not thread safe. They shouldn’t be initialized in one thread and accessed from a different thread.
Multi-Context Core Data Stack
Let’s explore this concept of thread confinement further through a specific example. I have created a sample app to demonstrate how to track and fix these violations. Go ahead and clone the repo from Github or browse the code online to follow along. Figure below shows the Core Data stack for the sample app.
This setup is inspired by a wonderful...
Continue reading →