I am developing a iOS app in which I am using Core Data. I am downloading data from a web service. Initially I have a table in which there is a field “to”. When data for one table is completed, I want to update “to” field of the table with a count of data that have been downloaded.
This is what I’ve used so far:
NSString *str;
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Resume" inManagedObjectContext:[self managedObjectContext]];
NSFetchRequest *request2 = [[NSFetchRequest alloc] init];
[request2 setEntity:entityDesc];
NSError *error;
NSArray *objects=[[self managedObjectContext] executeFetchRequest:request2 error:&error];
for (NSManagedObject *info in objects) {
str=[NSString stringWithFormat:@"%@",[info valueForKey:@"to"]];
int tableCount=[str intValue]+countValue;
NSLog(@"tableCount===%d",tableCount);
[info setValue:[NSNumber numberWithInt:tableCount] forKey:@"to"];
}
Either in the last line of your FOR loop or AFTER the FOR loop add the following line to save your changes in Core Data: