how to remove all objects from Core Data

前端 未结 7 1428
我寻月下人不归
我寻月下人不归 2020-12-09 23:04

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

[managedObjectContext deleteObject:objToDelete];

is it possible to delete all wit

7条回答
  •  暖寄归人
    2020-12-09 23:24

    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.

提交回复
热议问题