If you need to delete or flush all the data that exist in core data entity then use this method. Just pass the name of the Entity as a param to this method.
- -(void)flushEntity:(NSString*)entityName{
- NSFetchRequest *fetchAllObjects = [[NSFetchRequest alloc] init];
- [fetchAllObjects setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:self.myContext]];
- [fetchAllObjects setIncludesPropertyValues:NO]; //only fetch the managedObjectID
- NSError *erors = nil;
- NSArray *allObjects = [self.myContext executeFetchRequest:fetchAllObjects error:&erors];
- // uncomment next line if you're NOT using ARC
- // [allObjects release];
- if (erors) {
- NSLog(@"Error occurred1");
- }else
- NSLog(@"Error occurred1");
- for (NSManagedObject *object in allObjects) {
- [self.myContext deleteObject:object];
- }
- }
For
such more Blogs you can visit to http://findnerd.com/NerdDigest
No comments:
Post a Comment