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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:26:59+00:00 2026-05-13T01:26:59+00:00

I am trying to figure out the proper way to use NSManagedObjectContexts when you

  • 0

I am trying to figure out the proper way to use NSManagedObjectContexts when you are viewing, editing, and creating NSManagedObjects. I feel that the documentation and examples have explained how to use them in the most basic cases, but I’m not sure what the proper methods are in a slightly more complex setup.

The setup:

  • 3 main screens: a list of objects, an edit object screen, and a new object screen.
  • Another thread is downloading objects to add to the list in the background.

The requirements:

  • The list screen uses a MOC and an NSFetchedResultsController to get all it’s objects.
  • The edit and new object screens use MOCs to save/delete objects AND use NSFetchedResultsControllers for relationships.
  • The downloaded objects need a MOC to save it’s objects into Core Data (on the main thread).

The questions:

  • How many MOCs do I need?
  • How should I manipulate these MOCs?

Possible Answers:

  • Have one “View” MOC that is never edited and is used in the list screen. Use separate MOCs for the edit, new object screens, and the downloads. When these MOCs save, merge the changes back to the “View” MOC. This way any changes don’t affect the “View” MOC until they are saved. This is what I have been doing; it doesn’t seem to be working as smoothly as I hoped. There is a disconnect between the editing and the viewing and instead of being able to check on things when I know they might of changed I have to wait for NSFetchedResultsController delegate methods to finish and check on every possible thing that might have changed. It also makes it difficult if I need to change some data in the list view.

  • Have one MOC for everything. This is what I first tried but wasn’t sure of how to deal with the editing and creating. Now that I understand a bit more, I guess I could just edit the object or create an object and rollBack on cancel. On cimgf, I saw a post that seemed similar which said to create an undoGrouping around the edit/create and undo on cancel. Then I guess I could use a separate MOC on the downloaded objects because it might finish and save while the user is editing in the main MOC.

  • Anyways, the point is that I don’t know what the proper method is. Can you help me?

Example Disconnect for First Possible Answer

  1. Created an object (1) in the edit moc. Saved. Merged with view moc by notification.
  2. Created a new moc because I am downloading objects in the background. Updated some objects that are related to (1). Saved. Merged with view moc by notification.
  3. Edit (1) in the edit moc. Saved. Merged with view moc by notification.
  4. PROBLEM: Because the edit moc never got the new moc changes, when it saves, it deletes all the new moc changes affected by it.
  5. SOLUTION: I realize that I could also merge the changes to the edit moc or always use a new moc to edit things. However, I keep running into little things like this and having to find solutions, so it leaves me to believe that this is not the best answer.
  • 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-13T01:27:00+00:00Added an answer on May 13, 2026 at 1:27 am

    You should have at least one MOC per thread (they are not thread safe). So you could have a MOC for the downloader (in the background thread) and another in for the activity in the main thread list, edit and new.

    When you say there is a disconnect, can you be more specific? Are you using notifications (NSManagedObjectContextDidSaveNotification) and doing mergeChangesFromContextDidSaveNotification when you receive that notification. Remember, that mergeChangesFromContextDidSaveNotification should be performed on the main thread.

    In your view controller with NSFectchedResultsController are you handling all the cases of the NSFetchedResultsControllerDelegate correctly?

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

Sidebar

Related Questions

I'm trying to figure out the proper PBP approved way to process a multi
I'm basically trying to figure out the simplest way to perform your basic insert
Trying to figure out an equation to get the current group a page would
In trying to figure out this problem (which is still unsolved and I still
I'm trying to figure out how big a certain database would be (it hasn't
I'm trying to figure out why the control does not honor ZIndex. Example 1
I've been trying to figure out a regex to allow me to search for
I'm trying to figure out how to detect the type of credit card based
I'm trying to figure out what a Java applet's class file is doing under
I am trying to figure out this: c = 1 def f(n): print c

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.