删除(更新)coreData对象 [英] Deleting (updating) coreData objects
问题描述
我正在开发一个iOS应用程序,我使用 CoreData
来持久化我的数据。应用程序就像iBooks,我们可以下载一本书,读一本书,在书中记笔记,...对于这个我有很多实体 CoreData
( NoteEntity
,....)。
现在我有一个功能是删除用户下载的一本书(用户可以下载很多书,并且有一个功能删除一本书(例如有空格))。我的问题是,有一个简单的方法来删除所有的对象在CoreData(所有对象对应的书被用户删除)感谢您的答案。
关系删除规则:关系的删除规则指定如果尝试删除源对象,应该发生什么
。注意
上一句中的短语 - 如果尝试...。如果
关系的删除规则设置为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.
这篇关于删除(更新)coreData对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!