magicalpanda/MagicalRecord — Issue #141: Recommended approach for NSOperations and iOS 5
Author: robreuss
Created: 2012-02-10 16:48:21+00:00
State: open

I'm putting DB updates into an NSOperationQueue that get performed serially on a background thread. Sometimes a single NSOperation will involve creating multiple objects with child objects - in all cases, I want the entire collection of changes to be saved at the end of the process. This could involve 200 new entities and associated child entities.

I was wondering what the recommended practice with MR would be for making these types of updates in the background:

1. Obtain the context using **[NSManagedObjectContext MR_contextForCurrentThread]** and then when all the updates are made, call **MR_save** on that context.

2. Put everything inside a	**[MRCoreDataAction saveDataWithBlock:^(NSManagedObjectContext *localContext) {}];** block. Because I'm already on a background thread, I don't think I want to be using saveDataInBackgroundWithBlock.

I have tried both and both work, but tend to be unstable and produce mysterious crashes. For example, I'm currently using approach #1 and get an error where the app crashes inside "MR_cloudURLForUbiqutiousContainer", even though I'm not using iCloud at all.

This is a new app and I'm targeting iOS 5, so I have the flexibility to use whatever method is recommended and reliable for that context. Elsewhere in these discussions, people talk about tweaking the value **kCFCoreFoundationVersionNumber_iPhoneOS_5_0** - I'm completely unclear why folks are doing that and what the impact is.

As a side-note, **thanks so much** for this wonderful library - it has made a huge difference to me in being able to develop a large app in a more intuitive way.