adamgit / CoreDataStack

Simple classes to make Apple's Core Data usable for normal human beings
97 stars 14 forks source link

Concurrency with Core Data #2

Open langyufei opened 10 years ago

langyufei commented 10 years ago

I am not sure when but it seems Apple supports concurrency programming with Core Data in two ways: "There are two possible ways to adopt the pattern:

Create a separate managed object context for each thread and share a single persistent store coordinator. This is the typically-recommended approach.

Create a separate managed object context and persistent store coordinator for each thread. This approach provides for greater concurrency at the expense of greater complexity (particularly if you need to communicate changes between different contexts) and increased memory usage."

I know, it still requires us to carefully manage things. Do you available for updating the "CoreDataStack" in stead of an assertion in code?

reference: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/coredata/Articles/cdConcurrency.html#//apple_ref/doc/uid/TP40003385-SW1

adamgit commented 10 years ago

Yes - With iOS 6, Apple added new features for CoreData that make it (finally) safe to use multi-threaded.

However ... there were major bugs in those features (data-loss / corruption bugs in Apple's code!) that weren't fixed until the 6.1.x releases. It was very worrying that Apple was shipping core code with such bugs :(.

Unfortunately, Apple refuses to tell us what is "fixed" and what is "broken", so we have to guess - and risk our customers' data. I'm still testing to see what works/doesn't work on iOS7, and I'm aiming to do a major update / rewrite of CoreDataStack when I have more info.

In the meantime, I recommend selectively removing asserts etc as needed to make the classes work with iOS 6.1.x and iOS 7.x -- I've been using the new features, and they do make life a lot easier (when they work!)

ryanthon commented 8 years ago

Are there any plans on updating this class for new Core Data concurrency features?

adamgit commented 8 years ago

I wrote this mainly to work around bugs in Apple code, many of which (but not all) have now been fixed.

If I were using CoreData on a legacy project right now, I'd update it. But for anyone doing new projects, I'd hope its not necessary?

Some of the code is still useful, convenience stuff (I've used the choose-from-embedded-bundles on a few projects), but probably needs updating for iOS 9.

On 11 October 2015 00:32:34 Ryan notifications@github.com wrote:

Are there any plans on updating this class for new Core Data concurrency features?


Reply to this email directly or view it on GitHub: https://github.com/adamgit/CoreDataStack/issues/2#issuecomment-147136412