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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:15:57+00:00 2026-05-16T04:15:57+00:00

Original question has been answered. Update addresses related question raised in comments. Original post:

  • 0

Original question has been answered. Update addresses related question raised in comments.

Original post:

I am using the MOC save method used in Apple’s CoreDataBooks. However, I seem to have use for two layers of MOC merging (three MOCs where the 3rd merges with the 2nd and then the 2nd merges with 1st).

First, I have a tableview (ClassList) listing school classes. Selecting a class pushes a 2-row tableview (AddClass). At AddClass, the first row allows the user to edit the class title. Selecting the second row pushes a tableview (ClassRoster) that displays the student roster for that class. Lastly, selecting a student pushes on another 2-row tableview (AddStudent) where the user can edit the student name and username.

I can add and save classes successfully by using the dual MOC merge method (managedObjectContext and addingManagedObjectContext as employed by CoreDataBooks). I will call the “base MOC” in my first view “MOC1” and call the “scratchpad” MOC “MOC2”.

MOC2 temporarily stores changes made to a class object. These changes can then either be saved or canceled, sending a -didFinishWithSave:(BOOL) to the delegate. If I save, the changes made in MOC2 are merged with MOC1. That merge is working perfectly.

Handling changes made to student objects is where I’m going wrong. I thought I could employ MOC3 as a scratchpad for changes to student objects which would merge with MOC2 (when I saved a student object). MOC2 could in turn be saved with MOC1 when I saved the class object.

But I have run into errors with saving MOC3 and adding student objects to class objects because they are in different contexts. I can post code, but first I wanted to ask the bigger question: Am I going about this all the wrong way?

UPDATE:

Mr. Zarra recommended using initWithEntity:insertIntoManagedObjectContext: and setting the MOC to nil, thereby creating a temporary object which could later have its MOC set and saved.

Following his advice, I am attempting to incorporate the following code:

    NSManagedObjectModel *managedObjectModel - [[managedObjectContext persistentStoreCoordinator] managedObjectModel];
    NSEntityDescription *entity = [[managedObjectModel entitiesByName] objectForKey:@"MyClass"];
    MyClass *newClass = [[MyClass alloc] initWithEntity:entity insertIntoManagedObjectContext:nil];

I have run into an error, but I’m not sure it is related to this code yet. I will debug and post what I find.

  • 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-16T04:15:57+00:00Added an answer on May 16, 2026 at 4:15 am

    Yes. You do not need to use more than one NSManagedObjectContext. That example is a very poor one. In your case you should be using a single context and that will remove all of your issues.

    If you want a temporary entity, create it with a nil NSManagedObjectContext. When you want to save it you call -setManagedObjectContext: and then save that NSManagedObjectContext.

    The only time you realistically want to use more than one NSManagedObjectContext is when you are in a multi-threaded situation.

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

Sidebar

Related Questions

See the next post. This original one question content has been removed, as doesn't
I imagine this question has been asked and answered, but I cannot find it.
So this question has been asked before , but not answered in great detail.
This question has been edited for the second time: To view the original question,
This question has been edited to ask about a specific example as the original
The original question below has been overtaken by time: these days you do not
Due to the broad scope of the original question, the question's scope has been
Preamble So, this question has already been answered, but as it was my first
SEE EDIT UPDATES BELOW. Original question has been modified! I have a working window
Original question: The polysemy of a word is the number of senses it has.

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.