如何取消链接并删除 CoreData 中的相关对象

发布于 2024-08-16 06:13:25 字数 290 浏览 4 评论 0原文

我有一个核心数据实体,它与另一个实体具有排他的一对多关系。这种关系应该是第一个实体包含第二个实体中的一个或多个的基本包含。第二实体的实例只能包含在第一实体之一中。

我希望能够从第一个实体中删除所有包含的实体,然后删除它们。我该怎么做?我应该删除关系,然后为每个实体调用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-08-23 06:13:25

通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文