Skip to content

Instantly share code, notes, and snippets.

@darkseed
Created February 4, 2011 08:56
Show Gist options
  • Save darkseed/810891 to your computer and use it in GitHub Desktop.
Save darkseed/810891 to your computer and use it in GitHub Desktop.
- (void) deleteAllObjects: (NSString *) entityDescription {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:_managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *items = [_managedObjectContext executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
for (NSManagedObject *managedObject in items) {
[_managedObjectContext deleteObject:managedObject];
NSLog(@"%@ object deleted",entityDescription);
}
if (![_managedObjectContext save:&error]) {
NSLog(@"Error deleting %@ - error:%@",entityDescription,error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment