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 6597413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:12:20+00:00 2026-05-25T18:12:20+00:00

I am importing data from a web service, in such data I have a

  • 0

I am importing data from a web service, in such data I have a tree of categories.

For example:

   Restaurants
     – Italian
     – Mexican
     – Steakhouse

In my model I have set a relation called ParentCategory with an inverse relation called Subcategories. Everything is good so far.

Now, when I am importing my categories I am doing something like this: (Note: My code does not look like this. I have changed it to exemplify my problem)

NSEntityDescription *categoryEntity = [NSEntityDescription entityForName:@"Categories" inManagedObjectContext:context];

NSDescription *parentCategory = [NSEntityDescription insertNewObjectForEntityForName:[categoryEntity name] inManagedObjectContext:context]

//Then I actually set some values for parentCategory.
//Then create the subcategories. 

NSDescription *italianDescription = [NSEntityDescription insertNewObjectForEntityForName:[categoryEntity name] inManagedObjectContext:context];
[italianDescription objectForKey:@"Italian" forKey:@"name"];

//Set the relationship
[italianDescription objectForKey:parentCategory forKey:@"ParentCategory"];

//All this works great but then when 
NSEntityDescription *mexicanDescription = [NSEntityDescription insertNewObjectForEntityForName:[categoryEntity name] inManagedObjectContext:context];
[mexicanDescription objectForKey:@"Mexican" forKey:@"name"];
[mexicanDescription objectForKey:parentCategory forKey:@"ParentCategory"];

It seems like when that last line of code runs it removes the relation from “italianDescription”, therefore after I save my context it shows like it doesn’t have a parent category. I removed some data from my web service and only the last subcategory that I set the relation to parent category object X keeps it. All previous will loose it.

I checked the apple developer documentation and it doesn’t really help. That being said, how can I overcome this? Or what would be a efficient way to import that with relations.

  • 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-05-25T18:12:21+00:00Added an answer on May 25, 2026 at 6:12 pm

    I don’t think you are setting anything, the way to set values for NSManagedObjects is

    setValue: forKey:
    

    Instead of NSDescription*’s you should be using NSManagedObject*

    You may want to look into subclassing your entities as it allows for much easier access and setting of properties. In which case it would be

    MyCustomEntity* myobj=[NSEntityDescription insertNewObjectForEntityForName:@"MyentityName" inManagedObjectContext:context];
    

    Then you can set the values just by using it’s properties with dot notation or messaging. You can do this by selecting the entity in the core-data editor and then under Editor on the Menu bar there is an option to create a NSManagedObject subclass, after you create that you need to tell the entity that it has a custom class now. This is done in the right hand Utiliies bar under Entity there is a Class field, just enter the name of your new class and it should be set up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am importing a bunch of data from a web service on a background
I have a web form used for importing data from a CSV file. It
So, there have been several posts here about importing and saving data from an
I am importing massive amounts of data from Excel that have various table layouts.
I'm working on a web service that fetches data from an oracle data source
[edit] We're collecting credit application data from users on a web form. I have
In SSIS,I had tried to deploy a package, which is for importing data from
I'm importing some data from a CSV file, and numbers that are larger than
My application is storing location data from GPS inputs. When importing a GPX file,
I'm importing from a CSV and getting data roughly in the format { 'Field1'

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.