코어 데이터의 일부 레코드를 업데이트해야합니다. 이것이 올바른 방법일까요?목표 C - 코어 데이터 레코드 업데이트
NSManagedObjectContext *context = [self managedObjectContext];
NSMutableArray *poiFromCD=(NSMutableArray *)[self takePoiFromCoreData];
for (int i=0; i<[array count]; i++) {
for (int j=0; j<[poiFromCD count]; j++) {
Poi *poi=(Poi *)[poiFromCD objectAtIndex:j];
if ([[[array objectAtIndex:j]objectForKey:@"poiID"]isEqualToString:poi.poiID]) {
Poi *p=[poiFromCD objectAtIndex:j];
p.poiID=[[array objectAtIndex:i]objectForKey:@"poiID"];
p.lastmod=[[array objectAtIndex:i]objectForKey:@"lastmod"];
} else {
Poi *p;
p=[NSEntityDescription insertNewObjectForEntityForName:@"Poi" inManagedObjectContext:context];
p.poiID=[[array objectAtIndex:i]objectForKey:@"poiID"];
p.lastmod=[[array objectAtIndex:i]objectForKey:@"lastmod"];
}
}
}
NSError *error;
if (![context save:&error]) {
NSLog(@"Errore durante il salvataggio: %@", [error localizedDescription]);
}
나는 나의 방법에 배열을 전달, 그리고 난 이미 CoreData에 있고 poiFromCD에 넣어 데이터를 가지고.
내가 잘못했다면 올바른 길을 가르쳐주십시오. :)