使用 NSManagedObjectContext 清除整个核心数据
我在我的应用程序中使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以逐个实体地删除所有内容,也可以清除存储文件本身。
请参阅此解决方案:删除/重置核心数据中的所有条目?
You can either delete everything entity-by-entity or clear the store file itself.
See this solution: Delete/Reset all entries in Core Data?
只需删除该文件并重新创建持久存储,然后一切都很好并且是空的。
Just delete the file and recreate your persistent store, then everything is nice and empty.