How can I update data corresponding to any开发者_如何学Go key in Core Data?
Thanks
For updating any entry in core data you need first fetch that entry then make object for that entity then set all properties of that see this code,
NSMutableArray *fetchResults;
NSString *entityName=@"YourEntity";
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:globalManagedObjectContext];
[fetchRequest setEntity:entity];
fetchResults = [NSMutableArray arrayWithArray:[globalManagedObjectContext executeFetchRequest:fetchRequest error:nil]];
[fetchRequest release];
[fetchResults filterUsingPredicate:[NSPredicate predicateWithFormat:@"id==%@",comparing_key]];
objEntity=[fetchResults objectAtIndex:0];
objEntity.pro1=@"some value";
objEntity.pro2=@"some value";
if (![globalManagedObjectContext save:nil])
NSLog(@"Error in storing to database");
精彩评论