我是一个iOS新手。我正在使用以下函数将新行插入到我的数据库中 -
-(void)insertMetricAction:(NSString *)action andValue:(NSString *)value andStatus:(NSString *)status
{
MetricDb *aDbMessage = (MetricDb *)[NSEntityDescription
insertNewObjectForEntityForName:@"Metric"
inManagedObjectContext:localObjectContext];
aDbMessage.action=action;
aDbMessage.value=value;
aDbMessage.status = status;
double timeInMilliSec=[[NSDate date] timeIntervalSince1970]*1000;
NSString* timeStamp = [NSString stringWithFormat:@"%.0f" ,timeInMilliSec];
aDbMessage.timeStamp=timeStamp;
NSError *error;
if (![localObjectContext save:&error]) {
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0) {
for(NSError* detailedError in detailedErrors) {
NSLog(@" DetailedError: %@", [detailedError userInfo]);
}
}
else {
NSLog(@"***Getting database error. Error: %@",[error userInfo]);
}
}
}
相反,如果我想获取现有行并只编辑状态,我将如何使用 iOS 函数来做到这一点?