如何从Core Data中删除所有对象 [英] how to remove all objects from Core Data

查看:116
本文介绍了如何从Core Data中删除所有对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除所有对象?我知道我可以通过

删除一个

  [managedObjectContext deleteObject:objToDelete]; 

是否可以删除所有而不迭代所有数组?
感谢

解决方案

标记要删除的对象,然后保存工作方式,因为核心数据仍然需要运行所有正在删除的对象的验证规则。毕竟,对象可以根据它对 -validateForDelete:的响应来拒绝删除。



如果:
$ b $ b

然后:




  • 删除使用该持久性存储的Core Data堆栈

  • 并删除持久存储的文件。


how can I remove all objects? I know I can remove one by

[managedObjectContext deleteObject:objToDelete];

is it possible to delete all without iterating all array? thanks

解决方案

Marking objects for deletion and then saving works the way it does because Core Data still needs to run the validation rules for all of the objects being deleted. After all, an object can refuse deletion based on how it responds to -validateForDelete:.

If:

  • you truly want to delete everything in a persistent store
  • and you don't care about whether the objects in that persistent store say they're valid for deletion

Then:

  • tear down the Core Data stack that's using that persistent store
  • and delete the persistent store's file.

这篇关于如何从Core Data中删除所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆