0

I have issues to let fetch results controller (using magicalrecord) observe the changes from restkit's mapping result. Only when I use the context from restkit and update to the magically record's default context (then use it in the fetch results controller), the new inserts or changes will be updated to table view.

Here is what I have done, not sure if it is ok?

NSManagedObjectContext* context = [[RKObjectManager sharedManager].objectStore managedObjectContextForCurrentThread];
[NSManagedObjectContext MR_setRootSavingContext:context];
[NSManagedObjectContext MR_setDefaultContext:context];
angelokh
  • 9,426
  • 9
  • 69
  • 139

1 Answers1

1

You don't want to set the root saving context. Try setting that to nil. Since you are basically ignoring MagicalRecord, I would advise against this as well. What about making the RestKit Managed object context a child of the default context, or root saving context....or visa versa?

casademora
  • 67,775
  • 17
  • 69
  • 78
  • I tried put MagicalRecord's context a child of Restkit's context. However, when restkit fetched and sync from server, those records will not be populated to MagicalRecord's context. – angelokh Aug 03 '12 at 16:30
  • The above method is working for me. Could you explain why you are against setting context to MagicalRecord? – angelokh Aug 03 '12 at 16:32
  • MagicalRecord has a set architecture for use with nested contexts. While the API does let you change the default context, it's not really meant to do that. Have you tried making the RKContext a child of the root saving context, and then setting the context as the default? I don't use RestKit myself, so I don't know about all these use cases. – casademora Aug 03 '12 at 22:53
  • I did not try this way. However, there is one concern. The RKContext is listening to NSManagedObjectContextDidSaveNotification. I am not sure if any issue will be introduced if I make the RKcontext becomes a child of MagicalRecord's context? – angelokh Aug 03 '12 at 23:09
  • The other issue I am facing is context save. I can't change RK to also save parent context when RK saves its own context. To save parent's context at the same time is recommended, please see http://stackoverflow.com/a/9793131/772481. – angelokh Aug 03 '12 at 23:24