仅当满足布尔条件,restkit尝试更新记录时才更新或保存托管对象

编程入门 行业动态 更新时间:2024-10-22 22:55:02
本文介绍了仅当满足布尔条件,restkit尝试更新记录时才更新或保存托管对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的 Answers实体中有 syncState 布尔属性,该属性未映射。我使用 RkEntity Mapping 从服务器获取答案实体的记录。仅当的 syncState 已经存在时,我想保存/更新已经存在的记录记录将进行 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尝试更新记录时才更新或保存托管对象

本文发布于:2023-10-24 13:58:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524113.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔   时才   对象   条件   restkit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!