这是我使用核心数据更新表的代码
NSEntityDescription *entityDesc=[NSEntityDescription entityForName:@"UsageData" inManagedObjectContext:context];
NSFetchRequest *request=[[NSFetchRequest alloc] init];
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"(member_id=Null)"];
[request setPredicate:predicate];
[request setEntity:entityDesc];
UsageData *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];
UsageData *data=(UsageData *)matches;
NSLog(@"Data before===%@",data);
[data setMember_id:memberKey];
// [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;
我也想将这些更改保存到数据库中,日志给出了正确的想法,但我的本地 sqlite 数据库没有更新,有人知道吗?提前致谢..