Monday, March 30, 2015

Zarra’s Core Data Stack

Marcus Zarra creates a private queue context for writing to disk and a main queue (child) context for all user interaction:

To protect our main thread, we call -addPersistentStoreWithType: configuration: URL: options: error: in a dispatched background block. This will allow our -initializeCoreData method to return immediately, even if the persistent store needs to do some additional work. However, the user interface needs to know when it is safe to access the persistence layer. Therefore we need to use the callback block that was given to us.

[…]

The proper way to get access to the persistence controller is to inject it into each view controller as they are built and accessed.

[…]

The occasions where I don’t use this stack usually involve large data manipulation. When I need to process a tremendous amount of data into the Core Data stack and that data can be isolated away from the User Interface.

Update (2018-09-04): Stichting CocoaHeadsNL:

Dmitrii Ivanov gives us an insight view of the experience that the Qardio iOS team has gained over the years by using Core Data. He explains the issues they’ve had with Core Data, the different stacks you can use and their implementation and performance differences.

1 Comment RSS · Twitter

[…] particular note is that, contra Zarra, he thinks child contexts are usually […]

Leave a Comment