简体   繁体   English

RestKit /核心数据-重置后备存储中的对象,而不更新

[英]RestKit / Core Data — reset objects in backing store, not update

I'm running into a problem with updating objects in my local backing store in my iOS app. 我在iOS应用程序的本地后备存储中更新对象时遇到问题。 Lets say I have an object (in JSON format) 可以说我有一个对象(JSON格式)

{
  attr1: 'Hello',
  attr2: 'World'
}

The corresponding NSManagedObject in my iOS app has two attributes: NSString *attr1 and attr2. 我的iOS应用程序中对应的NSManagedObject具有两个属性:NSString * attr1和attr2。 On this initial JSON push, the object gets the correct values 'Hello' and 'World' in attr1 and attr2. 在此初始JSON推送中,对象在attr1和attr2中获得正确的值'Hello'和'World'。 The next from my backend server message returns the following JSON: 我的后端服务器消息中的下一条返回以下JSON:

{
  attr1: 'Hello2'
}

This updates my object's attr1 to 'Hello2', but my attr2 stays the same (ie 'World'). 这会将我对象的attr1更新为“ Hello2”,但我的attr2保持不变(即“世界”)。 I want this to be nullified. 我希望将此无效。 In other words, I don't want an 'update' to my NSManagedObject, but rather I want a full reset. 换句话说,我不想对我的NSManagedObject进行“更新”,而是想要完全重置。 Is there a way to accomplish this? 有没有办法做到这一点? I have tried a few things like explicitly nullifying attributes and saving the NSManagedObjectContext, but this way doesn't seem to persist. 我已经尝试了一些事情,例如显式地使属性无效并保存NSManagedObjectContext,但是这种方法似乎并不持久。 Am i missing anything? 我有什么想念的吗?

You are doing the right thing. 您做对了。 Nullify "manually" (or by automating this inside the NSManagedObject subclasses), and save to persist. “手动”无效化(或通过在NSManagedObject子类内部自动化),然后保存以持久化。

If you are not seeing what you expect the error must be in the way you are saving, or in the way you are showing the data. 如果您没有看到期望的结果,则错误必定是保存方式或数据显示方式。 Or maybe your object got updated again before being shown. 也许您的对象在显示之前再次进行了更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM