Jakub Průša Jakub Průša - 24 days ago 4
iOS Question

Saving context for every action

I have network park of my application which discovering devices in network and inserting into coredata through Magical Record. But this is happened on some other thread not main thread. Also I have UITableView with fetchresultcontroller which showing devices in table view. But only option how to let fetchRequestController now about my changes was, calling this:

[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];

After every change. Missing I am something, or is this correct way how to make it?


[MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext){
MyCDDevice * localDevice = [MyCDDevice MR_createEntityInContext:localContext];
[localDevice initFromDictionary:dictionary];

[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];


Save on every whole data operation, which is recommended by MagicalRecord. After saveWithBlockAndWait:, it is saved to persistent store, so there is no need to MR_saveToPersistentStoreAndWait.