I have a plist of values I want to read into Core Data. I can read in the \"top level,\" but along with strings and numbers, each item also contains dictionaries. I am havin
You are not creating a new managed object for each Plant
dictionary value. You are just trying to assign the dictionary itself to the relationship which, of course, will not work.
You need to add something like:
[gardenManObj setValue:[thisGardenDictionary objectForKey:@"rating"] forKey:@"rating"];
NSDictionary *thisGardenPlantsDictionary = [thisGardenDictionary objectForKey:@"plants"];
NSLog(@"thisGardenPlantsDictionary contains %i dictionaries.", [thisGardenPlantsDictionary count]);
NSManagedObject *plantMO;
for (Plant *eachPlant in thisGardenPlantsDictionary) {
plantMO=[NSEntityDescription insertNewObjectForEntityForName:@"Plant" inManagedObjectContext:context];
[plantMO setValue:[eachPlant valueForKey:@"someValue" forKey:@"someKey"]];
//... repeat for all attributes
[plantMO setValue:gardenManObj forKey:@"gardent"];
}
... that will create the necessary Plant
objects and set the relationship with the correct Garden
object.