데이터를 코어 데이터에 저장하려고합니다. (주 모델 및 관련 모델). 죽이기 후에 저장하면 주 모델은 저장되지만 관련 모델은 저장되지 않습니다. 나는 다음과 같은 코드를 가지고 : 나는 인수가 저장되지 않는 응용 프로그램을 죽일 때관련 데이터 저장 코어 데이터
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가 문제를 일으킬 수 있습니까 ??
은 확실 locations.count'가 큰 '것을 있습니까 0보다? –