我正在尝试将数据保存到核心数据中。(主要型号及相关型号)。当我保存杀死主模型后保存但未保存相关模型时。我有以下代码:
NSManagedObjectContext *context = [self managedObjectContext];
Trace *trace = [NSEntityDescription
insertNewObjectForEntityForName:@"Trace"
inManagedObjectContext:context];
trace.totalDistance = self.totalDistance;
trace.averageSpeed = self.averageSpeed;
trace.theBestSpeed = self.theBestSpeed;
trace.stopTime = [NSNumber numberWithInt: self.stopTime];
trace.time = self.time;
NSMutableArray *nsa = [[NSMutableArray alloc] init];
for (int i=0;i<locations.count;i++){
CLLocation* cl =(CLLocation*) locations[i];
Argument *point = [NSEntityDescription
insertNewObjectForEntityForName:@"Argument"
inManagedObjectContext:context];
point.latitude = [NSNumber numberWithDouble: cl.coordinate.latitude];
point.langitude = [NSNumber numberWithDouble: cl.coordinate.longitude];
point.speed = self.speeds[i];
[nsa addObject:point];
}
NSOrderedSet * ns = [[NSOrderedSet alloc] initWithArray:nsa];
trace.points = ns;
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
当我杀死一个应用程序时,不会保存参数,但会保存跟踪。Shat会导致问题吗?