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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:12:15+00:00 2026-06-10T23:12:15+00:00

I’ve seen a few videos / threads that say it’s possible to create ‘children’

  • 0

I’ve seen a few videos / threads that say it’s possible to create ‘children’ MOCs — MOCs that use other MOCs as their persistant stores. Useful, for example, in a context where you’re threading your application, and want to have a single master MOC that can save / rollback the changes that the child threads create. (From what I understand, a MOC and it’s managedObjects MUST all be used on the same thread)

The question is, how do I create a child MOC? I can’t track down the WWDC videos I was watching that introduced them, and everything I”ve seen has been talking about how to use them ONCE they’re made. I can easily alloc a new MOC, but how do I set it’s persistent store to be another MOC? The reference doesn’t show any functions that do that!

  • 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-10T23:12:16+00:00Added an answer on June 10, 2026 at 11:12 pm

    Create a new MOC for which you are in total control of the synchronization. This is the same as calling init and the same behavior as pre-parent/child relationships.

    NSManagedObjectContext *moc = [[NSManagedObjectContext alloc]
           initWithConcurrencyType:NSConfinementConcurrencyType];
    

    You parent a MOC to another MOC by setting its property:

    moc.parentContext = someOtherMocThatIsNowMyParent;
    

    Here, the child chooses the parent. I’m sure my kids wish they were NSManagedObjectContexts. A parent context must be of either NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType.

    You can create a MOC that is “bound” to a private queue:

    NSManagedObjectContext *moc = [[NSManagedObjectContext alloc]
           initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    

    which means you should only access it via the performBlock or performBlockAndWait API. You can call those methods from any thread as they will ensure proper serialization of the code in the block. For example…

    NSManagedObjectContext *moc = [[NSManagedObjectContext alloc]
           initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    moc.parentContext = someOtherMocThatIsNowMyParent;
    [moc performBlock:^{
        // All code running in this block will be automatically serialized
        // with respect to all other performBlock or performBlockAndWait
        // calls for this same MOC.
        // Access "moc" to your heart's content inside these blocks of code.
    }];
    

    The difference between performBlock and performBlockAndWait is that performBlock will create a block of code, and schedule it with Grand Central Dispatch to be executed asynchronously at some time in the future, on some unknown thread. The method call will return immediately.

    performBlockAndWait will do some magic synchronization with all the other performBlock calls, and when all the blocks that have been presented prior to this one are done, this block will execute. The calling thread will pend until this call has completed.

    You can also create a MOC that is “bound” to the main thread, just like private concurrency.

    NSManagedObjectContext *moc = [[NSManagedObjectContext alloc]
           initWithConcurrencyType:NSMainQueueConcurrencyType];
    moc.parentContext = someOtherMocThatIsNowMyParent;
    [moc performBlock:^{
        // All code running in this block will be automatically serialized
        // with respect to all other performBlock or performBlockAndWait
        // calls for this same MOC.  Furthermore, it will be serialized with
        // respect to the main thread as well, so this code will run in the
        // main thread -- which is important if you want to do UI work or other
        // stuff that requires the main thread.
    }];
    

    which means you should only access it directly if you know you are on the main thread, or via the performBlock or performBlockAndWait API.

    Now, you can use the “main concurrency” MOC either via the performBlock methods, or directly if you know you are already running in the main thread.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.