Skip to content

Instantly share code, notes, and snippets.

@asparagui
Created August 27, 2012 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asparagui/3485013 to your computer and use it in GitHub Desktop.
Save asparagui/3485013 to your computer and use it in GitHub Desktop.
- (void) deleteAllObjects: (NSString *) entityDescription {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *items = [context executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *managedObject in items) {
[context deleteObject:managedObject];
//NSLog(@"%@ object deleted",entityDescription);
}
if (![context save:&error]) {
//NSLog(@"Error deleting %@ - error:%@",entityDescription,error);
}
}
-(void) removeAllContent
{
NSLog(@"deleting ALL core data content!");
[self deleteAllObjects:kBlahEntity];
....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment