这是我编辑特定属性并将其保存到 sqlite 数据库的代码,但我无法将更改保存到数据库。
-(void)changeMemberKey
{
NSEntityDescription *entityDesc=[NSEntityDescription entityForName:@"Table1" inManagedObjectContext:context];
NSFetchRequest *request=[[NSFetchRequest alloc] init];
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"(member_id=Null)"];
[request setPredicate:predicate];
[request setEntity:entityDesc];
Table1 *matches;
NSError *error;
NSArray *objects=[context executeFetchRequest:request error:&error];
NSLog(@"Object count===%d",[objects count]);
for(int i=0;i<[objects count];i++)
{
matches=[objects objectAtIndex:i];
Table1 *data=(Table1 *)matches;
NSLog(@"Data before===%@",data);
[data setValue:memberKey forKey:@"member_id"];
[context save:&error];
NSLog(@"Data after====%@",data);
data=nil;
}
entityDesc=nil;
request=nil;
matches=nil;
error=nil;
objects=nil;
}