我认为这是错误的,它只加载一个汽车零件:此方法采用两个数组,一个带有汽车名称,一个带有零件,创建一辆新汽车,并将汽车零件添加到其中,然后将汽车保存到核心数据中。(目前不以这种方式工作)
for (int i=0; i<[massiveArray count]; i++) {
//create a new car and part
Car*newCar =(Car*)[NSEntityDescription insertNewObjectForEntityForName:@"Car" inManagedObjectContext:[self managedObjectContext]];
CarPart *part =[NSEntityDescription insertNewObjectForEntityForName:@"CarPart" inManagedObjectContext:[self managedObjectContext]];
//set car title to string title in array of titles
[newCar setValue:[massiveArray objectAtIndex:i] forKey:@"name"];
//go through car parts array and add all new parts for that specific car
for (int i=0; i<[partNamesArray count]; i++) {
[part setValue:[partNamesArray objectAtIndex:i] forKey:@"name"];
[newCar addToCarPartObject:part];
//save each part??? I think this is wrong
[self.managedObjectContext save:nil];
}
//Save new car
[self.managedObjectContext save:nil];
}