如何取消链接并删除 CoreData 中的相关对象
我有一个核心数据实体,它与另一个实体具有排他的一对多关系。这种关系应该是第一个实体包含第二个实体中的一个或多个的基本包含。第二实体的实例只能包含在第一实体之一中。
我希望能够从第一个实体中删除所有包含的实体,然后删除它们。我该怎么做?我应该删除关系,然后为每个实体调用deleteObject,还是为每个包含的实体调用deleteIObject 会导致正确设置关系。如果第二个为真,我可以枚举包含的实体并调用deleteObject,还是应该首先复制该集合(如果为每个对象调用deleteObject会切断关系,这将修改正常枚举中不允许的集合)。
I have a core data entity which has an exclusive one to many relationship with another entity. This relationship is supposed to be a basic containment the first entity contains one or more of the second. An instance of the second entity can only be contained in one of the first entities.
I want to be able to remove all the contained entities from the first entity and then delete them. How should I do this? Should I remove the relationship and then call deleteObject for each entity or will calling deleteIObject for each contained entity cause the relationship to be set correctly. If the second is true, can I just enumerate the contained entities and call deleteObject or should I first make a copy of the set (if calling deleteObject for each objects severs the relationship this will modify the set which is not allowed in normal enumeration).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 NSManagedObjectContext 删除每个子对象,关系将相应地清理。这是假设您遵循约定并将所有关系配置为双向。
Delete each child object via the
NSManagedObjectContext
and the relationship will clean up appropriately. This is assuming that you are following the convention and have all of your relationships configured to be bi-directional.