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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:55:44+00:00 2026-05-12T13:55:44+00:00

I am trying to import a set of data into a CoreData persistentStore. This

  • 0

I am trying to import a set of data into a CoreData persistentStore. This is read-only data that will be presented to the user at run-time.

I have an entity called “Category” that has a one-to-many relationship with an entity called “Item”, which in turn has an inverse relationship to a Category.

As I add Items to the context, how do I associate them with the correct Category? I can see in the SQLite dB that it is done by adding a Category field to the Item table, and probably uses the Categories primary key for the relationship. But the PK is behind-the-scenes… is there a method for making the connection?

I also see in my Category class that there are methods generated by CoreData for adding Items, but I am assuming that these are alos behind-the-scene methods that allow CoreData to maintain the relationships:

    @interface Category (CoreDataGeneratedAccessors)

- (void)addItemObject:(Item *)value;
- (void)removeItemObject:(Item *)value;
- (void)addItems:(NSSet *)value;
- (void)removeItems:(NSSet *)value;

@end

I read in the programing guide that CoreData takes care of the other side of the relationship automatically, but I can’t figure out how do do the initial link to a Category as I add Items.

Thanks

jk

  • 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-12T13:55:45+00:00Added an answer on May 12, 2026 at 1:55 pm

    There are different possibilities. If you already have a Category object (for instance obtained through a fetch request), and assuming the variables

    Category *category;
    Item *item;
    

    then you simply do the following:

    item.category = category;
    

    or

    [category setValue: category forKey:@"category"];
    

    and you are done, since Core Data automatically sets the inverse relationships.

    If you do not have a Category object, or you want to insert a new one, do the following:

    // Create a new instance of the entity 
    Category *category = (Category *) [NSEntityDescription insertNewObjectForEntityForName:@"Category" inManagedObjectContext:managedObjectContext];
    // add all of the category properties, then set the relationship
    // for instance set the category name
    [category setValue:@"myCategoryName" forKey:@"name"];
    [category setValue:item forKey:@"item"];
    

    Then you set this Category object for your Item object exactly as before.
    Finally, the methods you have shown are not used behind the scenes by Core Data: these methods are available to you, so that you can also do the following:

    [category addItemObject:item];
    

    or the inverse:

    [item addCategoryObject:category];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to import an excel file into a data table using GemBox
I’m trying to import fixed width data from text file into SQL Server Express
I have some CSV data files that I want to import into mySQL. I
ok so I am trying to parse XML data into a table, this is
I'm trying to implement some code to import user's data from another service via
I'm trying to import a large data set (~6,000) in to my core data
I am trying to import data from a utf-8 encoded flat file into SQL
I have a set of files I am trying to import into MySQL. Each
I'm trying to import some data into R and not having much luck grouping
I'm trying to import about 10K rows of UTF-8 encoded data into a new

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.