jksk / NLCoreData

Library that wraps Core Data for iOS for easier and more readable operations.
MIT License
82 stars 12 forks source link

Child parent contexts #4

Closed atlithorn closed 11 years ago

atlithorn commented 11 years ago

Excellent project sir. We have had serious problems with child contexts in our apps, pretty much the same as explained here

http://wbyoung.tumblr.com/post/27851725562/core-data-growing-pains

NLCoreData obviously provides a bypass via storeContext which solves the problem for us but I was more wondering what your thoughts on this are? Do you use child contexts yourself?

kevinrenskers commented 11 years ago

+1 for some info on this

jksk commented 11 years ago

I'm not 100% sure which issue you're referring to. I haven't really noticed an issue with the backgroundContext blocking the mainContext. I do some heavy lifting, like saving a batch of binary objects (images, etc).

My method is generally: I never touch the storeContext directly. Batch insertions are done in the backgroundContext, only some simple editing in the mainContext. The backgroundContext does some fetching, mostly for uniquing purposes, but mostly it's about insertions and deletions, followed by a propagating save. The mainContext has a bunch of NSFetchedResultsControllers for keeping track of object changes.

atlithorn commented 11 years ago

It's not really an issue and especially not with your library, I just couldn't find another way to reach out.

We were using another 3rd party core data library (Magical Record) and were syncing to an external data source by simply truncating and re-inserting via the child context. We experienced a bunch of the issues listed in that blog post and narrowed it down to the child context and ended up removing the library, writing directly to a "storeContext".

Child contexts are a beautiful idea but we're scared to use them after that run in and I just wanted to get your take on the matter. We will be using NLCoreData in the future because it takes away so much of the boilerplate and gives us the storeContext which was the only way we were able to fix the issue for us.

If you're interested I can see about creating a test app to demonstrate the issue via NLCoreData.

jksk commented 11 years ago

If you feel like creating a demo app, that'd be great. I can't promise I'll find a workaround, but at the very least it'd be a learning experience.