RESTKit: Comparing GET object with locally persisted before overwriting

一个人想着一个人 提交于 2019-12-06 06:58:32

The below option doesn't work correctly because the MOC is saved even if the save isn't propagated up to the persistent store so you can't ask it about its changes. You could use multiple contexts with the same approach, but:

RestKit is able to use KVC validation. As such you can implement a number of methods on your model objects and add your validation logic. These methods are called with the new incoming data and have access to the current data (the instance variables of self) so you can check the incoming value and check if you want to:

  1. accept it
  2. change it
  3. abort the mapping altogether

See this ref.


From the MOC you can get updatedObjects. Once you have the updated objects you can get the changedValues for each. Now, using the keys from that dictionary, you can get the previous saved values with committedValuesForKeys:.

Now you have all the information required to make your comparison. You should process each of the keys and apply whatever logic you want. As part of the processing you can change some variables back to their saved values, or reset the entire object using refreshObject:mergeChanges:.

At the end of your processing, save the context.

You should not be using multiple different contexts to achieve this, though you should probably be using a different context from the standard main queue context.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!