0

Can any one tell me how to remove all the NSObject of CoreData at a same time ?

Currently i have done with for loop but i think it is not good way also taking more time when size of data is more, Thanks in advance.

Bucket
  • 449
  • 3
  • 20
  • Check this one http://stackoverflow.com/questions/1383598/core-data-quickest-way-to-delete-all-instances-of-an-entity – Nirav D Feb 23 '17 at 10:58
  • Check this link http://stackoverflow.com/questions/1077810/delete-reset-all-entries-in-core-data – Nidhi Patel Feb 23 '17 at 11:07

1 Answers1

0

You can still delete the file programmatically, using the NSFileManager:removeItemAtPath:: method.

NSPersistentStore *store = ...;
NSError *error;
NSURL *storeURL = store.URL;
NSPersistentStoreCoordinator *storeCoordinator = ...;
[storeCoordinator removePersistentStore:store error:&error];
[[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error];

Then, just add the persistent store back to ensure it is recreated properly.

The programmatic way for iterating through each entity is both slower and prone to error.

Just removing the store and recreating it is both fast and safe, and can certainly be done programmatically at runtime.

Matloob Hasnain
  • 1,025
  • 6
  • 21