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

  • Home
  • SEARCH
  • 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 9094957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:28:39+00:00 2026-06-16T23:28:39+00:00

I have from one side the NSManagedObject event that has a relationship one to

  • 0

I have from one side the NSManagedObject event that has a relationship one to many with the Entity Contacts.My app downloads contacts from the server, once all the contacts are downloaded I want to save them in CoreData keeping the relationship. Im wondering if I can save them in one go. All the contacts in an NSArray, contactsWeb, and push them into Core Data or I have to save each one of them like this:

NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

for(int i = 0; [contactsWeb count]; i++){

NSManagedObject *contact = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:context];

[contact setValue:[contactsWeb objectAtIndex:i] forKey:@"text"];
[contact setValue:[NSDate date] forKey:@"date"];

[[event mutableSetValueForKey:@"toContacts"]addObject:contact];
 NSError *error;
if(![context save:&error]){
    NSLog(@"%@", [error localizedDescription]);
}
}
  • 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-16T23:28:40+00:00Added an answer on June 16, 2026 at 11:28 pm

    Saving a managed object context means that all changes in the context are saved to the persistent store (or to the parent context, in the case of nested contexts). So you can (and should) save the context “in one go” after all contacts have been inserted and the relationships been set.

    Remark: If you create managed object subclasses Contacts and Event for your entities, your code can be simplified to

    Contacts *contact = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:context];
    contact.text = [contactsWeb objectAtIndex:i];
    contact.date = [NSDate date];
    [event addToContactsObject:contact];
    

    The managed object subclasses can be created in Xcode: Select the entities in the Core Data model editor and choose “Editor -> Create NSManagedObject subclass …” from the menu.

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

Sidebar

Related Questions

I have an app with CALayers that move from one side of the screen
I am creating a client side swing app that will have data provided by/from
I have a CSS3 position transition that makes a dive slide from one side
I have migrated Project server from one server to another. I am able to
I have a stored procedure that needs to return something from one of two
I have a lot of files from one side (A) and a lot of
I have it so that users can copy and paste objects from one page
I want to Create a Marquee that when text Exit from one Side and
At some point I must have moved files from one location to another using
I have taken a manifest from one of the answers posted here in SO

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.