Posted By

jodm on 02/01/11


Tagged

data clear delete coredata core


Versions (?)

Clear Core Data Table


 / Published in: Objective C
 

  1. - (void) deleteAllObjects: (NSString *) entityDescription {
  2. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  3. NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:_managedObjectContext];
  4. [fetchRequest setEntity:entity];
  5.  
  6. NSError *error;
  7. NSArray *items = [_managedObjectContext executeFetchRequest:fetchRequest error:&error];
  8. [fetchRequest release];
  9.  
  10.  
  11. for (NSManagedObject *managedObject in items) {
  12. [_managedObjectContext deleteObject:managedObject];
  13. NSLog(@"%@ object deleted",entityDescription);
  14. }
  15. if (![_managedObjectContext save:&error]) {
  16. NSLog(@"Error deleting %@ - error:%@",entityDescription,error);
  17. }
  18.  
  19. }

Report this snippet  

You need to login to post a comment.