Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:19:11+00:00 2026-06-10T18:19:11+00:00

Following Ray Wenderlich’s new tutorial I was able to get JSON data and store

  • 0

Following Ray Wenderlich’s new tutorial I was able to get JSON data and store it into Core data. I am having a really hard time understanding how to do this with relationships in Core Data though.

Here is my Data Model:

enter image description here

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 here is where I set the managedObject’s 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's a Dictionary/Array add logic here
            for(NSDictionary *dict in value){
                NSLog(@"QUESTION");
            }
        } else {
            //Set managedObject's key to string
            [managedObject setValue:value forKey:key];
        }
    }

I have taken a look at this question but I’m really confused how to connect the pieces together from the Ray Wenderlich examples. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:19:12+00:00Added an answer on June 10, 2026 at 6:19 pm

    In your for loop you are going to do some special handeling, if you’re dealing with a QuestionGroup you will know that an array on that object is questions (assuming it is the only array) so you can create a new Question object for each entry in the dictionary. This is going to break the genericness of the sync engine but you could go through some extra steps to regain it if desired.

    else if ([value isKindOfClass:[NSArray class]]) {
        if ([[managedObject entity] name] isEqualToString:@"QuestionGroup") {
            NSSet *questions = [NSMutableSet set];
            for (NSDictionary *question in value) {
                // create your question object/record
                NSManagedObject *questionManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Question" inManagedObjectContext:managedObjectContext];
                // setup your question object
                questionManagedObject.text = [question valueForKey:@"text"];
                // store all the created question objects in a set
                [questions addObject:questionManagedObject];
            }
            // assign the set of questions to the relationship on QuestionGroup
            [managedObject setValue:questions forKey:@"questions"];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im following Ray Wenderlich tutorial for instruments , but I don't know why the
I'm having a hard time following the ray-plane intersection described in the following page.
When I run rake db:seed ,something are broken! I get the following error: ray@ray-virtual-machine:~/ticketee$
I am following a tutorial on how to incorporate iAds into my app but
I'm new to iOS programming and I'm reading this tutorial to get along http://www.raywenderlich.com/1797/how-to-create-a-simple-iphone-app-tutorial-part-1
I am having a go at using RestKit by following this tutorial - RestKit
So, Im following this great tutorial at http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2 to get started with iOS programming.
I am following this guide developer instrument guide and RayWenderlich's tutorial to view and
I am following a tutorial on how to add iADS to an app. This
I am in the process of learning cocos2d-android. I have been following a tutorial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.