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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:45:37+00:00 2026-05-26T23:45:37+00:00

I am using two managed object contexts in my iOS app. The first context

  • 0

I am using two managed object contexts in my iOS app. The first context is the parent of the second, utilizing the new nested managed contexts model introduced in iOS 5. Both of these contexts were created with the NSMainQueueConcurrencyType.

What I am trying to achieve is a nice way to handle temporary additions and edits to my data that may or may not get saved and have a logical distinction where the main controller object owns the first context (parent) and the sub-controller owns the 2nd context (child). Changes are thusly bubbled up and the main controller can decide whether or not to save its context. The fact that my contexts are nested requires that they be setup not using the confinement pattern (NSConfinementConcurrencyType).

My question is: is this pattern I’m trying to implement flawed? I just read from multiple posts that using multiple contexts on the main thread is probably not the best idea most of the time. I’m also struggling to determine where I should be using performBlockAndWait: on my contexts. Should I use it every time a message is sent to a context, even if I’m sure I’m currently executing in the main thread? Does this include spots where I am creating a new NSManagedObject like so:

    [theManagedObjectContext performBlockAndWait:^
    {
        id *myObj = [NSEntityDescription insertNewObjectForEntityForName:@"MyEntity" inManagedObjectContext:theManagedObjectContext];
        // more stuff done here
    }];

What about spots where I make changes to my NSManagedObjects? Do I need to wrap those in a performBlockAndWait: as well? What about spots where I use an NSFetchedResultsController and send it the performFetch message?

Am I better off just using one context and figuring out how the undo manager works?

The documentation for these new Core Data features is very sparse from what I’ve seen…

  • 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-26T23:45:38+00:00Added an answer on May 26, 2026 at 11:45 pm

    My understanding is that you should always use the block methods, -performBlock: and -performBlockAndWait: when sending messages to an NSManagedObjectContext that was not initialized using the confinement pattern. Obviously which method you use will depend on your needs.

    As far as initializing both parent and child with the NSMainQueueConcurrencyType, this is only necessary if the child context is connected to the UI. If not, creating this child context to offload some non-essential work would be best suited on a private thread using the NSPrivateQueueConcurrencyType. You’re already using the block based methods, so the changes necessary should be minimal.

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

Sidebar

Related Questions

I have a Managed Object Context to which I add two different SQLite stores.
I currently am using two stylesheets to get my intended output. The first stylesheet
I am currently using two catch blocks after a try block. The first catches
What are the pros & cons of using Entity Framework 4.1 Code-first over Model/Database-first
Hia, I got a somewhat odd problem. Im using two managed Classes that relate
In Django I am using two applications: python manage.py startapp books python manage.py startapp
I am using git for windows to manage a local project. I have two
I'm using two different libraries in my project, and both of them supply a
I'm using two commercial libraries that are produced by the same vendor, called VendorLibA
I'm currently using two libraries (prototype and jQuery), thus I've implemented the jQuery noConflict

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.