删除(更新)cor​​eData对象 [英] Deleting (updating) coreData objects

查看:239
本文介绍了删除(更新)cor​​eData对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用程序,我使用 CoreData 来持久化我的数据。应用程序就像iBooks,我们可以下载一本书,读一本书,在书中记笔记,...对于这个我有很多实体 CoreData NoteEntity ,....)。
现在我有一个功能是删除用户下载的一本书(用户可以下载很多书,并且有一个功能删除一本书(例如有空格))。我的问题是,有一个简单的方法来删除所有的对象在CoreData(所有对象对应的书被用户删除)感谢您的答案。



创建一个级联删除关系。 /developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.htmlrel =nofollow>核心数据编程指南


关系删除规则:关系的删除规则指定如果尝试删除源对象,应该发生什么
。注意
上一句中的短语 - 如果尝试...。如果
关系的删除规则设置为Deny,则可能不会删除
源对象。再次考虑部门的
员工关系,以及不同的删除规则
具有的效果。



...



级联
删除关系目标处的
对象。例如,如果你
删除一个部门,同时在
同时解除该部门的所有员工。



I am developing an iOS application and i am using CoreData to persiste my data. The application is like iBooks, we can download a book, read a book, takes notes in the book,... and for this i have many entities in CoreData (NoteEntity,....). Now i have a functionality witch is removing a book downloaded by the user ( the user can download many books and there are a functionality to delete a book ( to have spaces for example)). My question is, is there a simple way to remove all the objects in CoreData ( all the objects corresponding to the book deleted by the user) Thanks for your answers.

解决方案

Create a "Cascade" delete relationship between the book and all objects associated with it.

From Core Data programming guide:

Relationship Delete Rules: A relationship's delete rule specifies what should happen if an attempt is made to delete the source object. Note the phrasing in the previous sentence—"if an attempt is made…". If a relationship's delete rule is set to Deny, it is possible that the source object will not be deleted. Consider again a department's employees relationship, and the effect that the different delete rules have.

...

Cascade: Delete the objects at the destination of the relationship. For example, if you delete a department, fire all the employees in that department at the same time.

这篇关于删除(更新)cor​​eData对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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