使用 NSManagedObjectContext 清除整个核心数据

发布于 2025-01-07 01:31:42 字数 195 浏览 4 评论 0原文

我在我的应用程序中使用 Core Data,

也许我的用户想要删除他们曾经保存的所有 NSManagedObjects,

那么 NSManagedObjectContext 是否有一种快速方法可以做到这一点,我的意思是,清除整个持久存储,或者换句话说,删除每个实体的所有对象,那么核心数据中就没有实际的对象(实体除外)?

多谢!

I am using Core Data in my app,

and maybe my users wants to delete all the NSManagedObjects that they once saved,

So is there a quick method of NSManagedObjectContext that can do this, I mean, clear the whole persistent store, or in another word,delete all objects of every entity, so there's no actual objects (except entities) in core data?

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

一花一树开 2025-01-14 01:31:42

您可以逐个实体地删除所有内容,也可以清除存储文件本身。

请参阅此解决方案:删除/重置核心数据中的所有条目?

You can either delete everything entity-by-entity or clear the store file itself.

See this solution: Delete/Reset all entries in Core Data?

維他命╮ 2025-01-14 01:31:42

只需删除该文件并重新创建持久存储,然后一切都很好并且是空的。

Just delete the file and recreate your persistent store, then everything is nice and empty.

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