Following the new Ray Wenderlich tutorial, I was able to get JSON data and save it in Core data. However, itβs very difficult for me to figure out how to do this with relationships in Core Data.
Here is my data model:

Here is my JSON:
{ "results": [ { "name": "Trivia 1", "objectId": "1000", "createdAt": "2012-08-31 18:02:52.249 +0000", "updatedAt": "2012-08-31 18:02:52.249 +0000", "questions": [ { "text": "Question 1" }, { "text": "Question 2" }, { "text": "Question 3" } ] } ] }
And finally, this is where I set the managedObject Value:
//Sets values for ManagedObject, also checks type - (void)setValue:(id)value forKey:(NSString *)key forManagedObject:(NSManagedObject *)managedObject { NSLog(@"TYPE: %@", [value class]); //If managedObject key is "createdAt" or "updatedAt" format the date string to an nsdate if ([key isEqualToString:@"createdAt"] || [key isEqualToString:@"updatedAt"]) { NSDate *date = [self dateUsingStringFromAPI:value]; //Set date object to managedObject [managedObject setValue:date forKey:key]; } else if ([value isKindOfClass:[NSArray class]]) { //<---This would be the array for the Relationship //TODO: If it a Dictionary/Array add logic here for(NSDictionary *dict in value){ NSLog(@"QUESTION"); } } else { //Set managedObject key to string [managedObject setValue:value forKey:key]; } }
I looked at this question , but I'm really confused about how to combine the fragments with Ray Wenderlich's examples. Any help would be greatly appreciated.
mkral source share