I have an NSOperation subclass which is downloading and importing data into CoreData.
Once I've done this I want to save the context and merge it into the default context.
The saving is not done in a block, it just does it synchronously as it's already in a BG thread.
Once I've done the changes which MR save method should I use?
There are dozens of them and not really sure what each one does.
Should I use...
- (void)save:
- (void)saveOnlySelfAndWait;
- (void)saveToPersistentStoreAndWait;
Or should I do all the changes in...
+ (void)saveUsingCurrentThreadContext...
I want it to be synchronous so that I can control the ending of the operation.
At least could someone explain the differences between the different saves.
I acknowledge that these methods aren't documented very well. However, they follow with the Core Data nested context model fairly well.
With MagicalRecord
don't use save:
on an NSManagedObjectContext
. MagicalRecord
has all those extra error handling, logging and completion handlers built in. You want to use those.
You seem to know where data needs to go (from one context to the root). It depends on your hierarchy as to which save method you need to use. If you are only one level deep (ie. in a child context of the defaultContext), saveOnlySelfAndWait
will save to the defaultContext
. Otherwise, saveToPersistentStoreAndWait
will traverse the hierarchy for you, all the way to the data store.
The andWait
methods are blocking calls. The calls with completion a handler are not. These are fairly straight forward in their use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With