Я пытаюсь записать данные из NSMutableArray в таблицу основных данных через цикл NSManagedObject for.Она записывает последнюю запись в массиве несколько раз, а не записывает каждую отдельную строку в массиве.
Я сделал быстрый цикл перечисления в массиве, чтобы подтвердить, что он имеет несколько отдельных строк.
Это текущая версия моего цикла кода:
//see if there were any matching rows from All_Game_Tips_List entity and of course there should be
if (fetchedObjectsForAttributes == nil) {
// do nothing as user1 does not have a saved profile
NSLog(@"error no matching rows found which sounds suspect");
}
else
{
for (id object in fetchedObjectsForAttributes ) {
NSLog(@"alltip_obj = %@", object);
NSLog(@"found exactly %i matching alltip records",[fetchedObjectsForAttributes count]);
//next need to write a couple of fields from the profile entity and some from All_Game_Tips_List entity to mytips table but first need to get all needed attributes for an attribute (e.g. name, tminus, etc) for an attribute
//then insert the new row
NSManagedObjectContext *contextForMyTips = [appDelegate managedObjectContext];
NSManagedObject *myTipsFromAllTips = [NSEntityDescription
insertNewObjectForEntityForName:@"My_Game_Tips_List"
inManagedObjectContext:contextForMyTips];
NSLog(@"start wri to mytips");
for (NSManagedObject *info in fetchedObjectsForAttributes) {
[myTipsFromAllTips setValue:[info valueForKey:@"alltip_name"] forKey:@"mytip_name"];
[myTipsFromAllTips setValue:[info valueForKey:@"alltip_alert_msg"] forKey:@"mytip_alert_msg"];
[myTipsFromAllTips setValue:[info valueForKey:@"alltip_description"] forKey:@"mytip_description"];
[myTipsFromAllTips setValue:[info valueForKey:@"alltip_id"] forKey:@"mytip_id"];
[myTipsFromAllTips setValue:[info valueForKey:@"alltip_tminus_amt"] forKey:@"mytip_tminus_amt"];
[myTipsFromAllTips setValue:[info valueForKey:@"alltip_impact_type"] forKey:@"mytip_impact_type"];
} // end of for NSManagedObject loop
//commit the insert
if (![contextForMyTips save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
} // looping through id
} // end of else
Мысли о том, почему он застрял на последней записи в массиве?