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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:11:30+00:00 2026-05-31T19:11:30+00:00

I have an entity which looks like this: Entityname = Country with the attributes

  • 0

I have an entity which looks like this:

Entityname = Country

with the attributes “city” and “person”.

Country *country = [NSEntityDescription insertNewObjectForEntityForName:@"Country" inManagedObjectContext:context];


    country.city = @"New York";
    country.person = @"Doug";
    country.person = @"Carry";
    country.person = @"Arthur";

I want to save more then one people in that City.

I am using the code posted above, but only the last person is saved.

How I can save more then one people in CoreData?

Hope you can help me.

  • 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-31T19:11:31+00:00Added an answer on May 31, 2026 at 7:11 pm

    An approach for solving your problem would be:

    1. Create 3 Entities: Country, City and Person
    2. Setup the properties for your entities (e.g. Country.name, City.name, Person.name etc) using the graphical tool of XCode
    3. Setup the relations between your Entities. You need a one-to-many from Country -> City [call it cities] and a one-to-many from City -> Person [call it persons] (See Apple’s documentation regarding this subject). Keep in mind that you will need to set the inverse relations as well.
    4. That’s where all the fun begins… Choose Editor > Create NSManagedObject subclass. Xcode then will generate the files based on your model. Now if you look at the header files, you should see among the generated methods something similar to this:

    …

    - (void)addPersonObject:(Person *)value;
    - (void)removePersonObject:(Person *)value;
    - (void)addPersons:(NSSet *)value;
    - (void)removePersons:(NSSet *)value;
    

    …

    From this point is quite obvious to figure out how to add multiple objects 🙂
    I know that all this may seem hard at first but once you get yourself into this you will really be able to manage complex object graphs easy and efficiently.
    I hope that this information will set you on the right track!

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

Sidebar

Related Questions

I have an entity which looks something like this: (I'm coding to the web
I have a Category class which looks like this: @Entity @Table(name = categories) public
I have an Entity that looks like this: class Privilege { /** * @Id
I have a DB which looks like this: 1st: CommissionsV2 (Table = Entity_Product_Point) This
I have Person entity which has composition with Location Entity @ManyToOne(fetch = FetchType.EAGER, cascade
I have an abstract entity called Block which contains two attributes: column and order
I'm trying to read in an xml file which looks like this <?xml version=1.0
I have a model that looks like this: public interface IEntity { int Id
I have a Model called Version that looks like this: from google.appengine.ext import db
I have a base class for all my entity types which is like public

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.