Hi guys, 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
Hi guys, 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
Just iterate the array and delete them. There isn't a defined method for deleting them all.
You can also just tear down the stack (releasing the NSManagedObjectContext
, NSPersistentStore
and NSManagedObjectModel
) and delete the file. Probably would be faster than iterating over your entire database and deleting each object individually.
Also, it is unlikely they will provide this functionality in the future because it is easy to delete the file. However if you feel it is important then file a radar and let Apple know. Otherwise they won't know how many people want this feature.
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:
Then: