仅当满足布尔条件,restkit尝试更新记录时才更新或保存托管对象 [英] Update or save managed object only when boolean condition is met , when restkit tries to update records

查看:59
本文介绍了仅当满足布尔条件,restkit尝试更新记录时才更新或保存托管对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Answers实体中有 syncState 布尔属性,该属性未映射。我使用 RkEntity Mapping 从服务器获取答案实体的记录。仅当 syncState 已经存在时,我想保存/更新已经存在的记录未同步,则c $ c>记录将进行 Synced 并忽略从服务器获取的记录。
我正在考虑覆盖 Answers实体 willSave 并忽略保存,但是该方法可用于更新一些记录,并避免避免保存托管对象。

I have syncState boolean attribute in my Answers Entity which is not mapped. I get records of Answer Entity from server using RkEntity Mapping. I want to save/update already existing records only if syncState of already existing records is Synced and ignore records fetched from server if syncState of already existing records is UnSynced. I was thinking of overriding willSave of Answers Entity and ignore saving but that method can be used to update some records and not avoid saving managed object.

推荐答案

您应使用 KVC验证,因为它允许您中止单个对象的映射,因此它们永远都不是保存对象,而不是尝试操作保存。特别是,您需要设置 discardsInvalidObjectsOnInsert

You should use KVC validation for this as it allows you to abort the mapping of individual objects so they are never candidates for saving rather than trying to manipulate the save. In particular, you need to set discardsInvalidObjectsOnInsert.

这篇关于仅当满足布尔条件,restkit尝试更新记录时才更新或保存托管对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆