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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:41:56+00:00 2026-06-04T08:41:56+00:00

I feel like I’ve read every CoreData question on Stack Overflow today, and am

  • 0

I feel like I’ve read every CoreData question on Stack Overflow today, and am still very very stuck. 🙂

I’m working on a application that uses CoreData that is based on the methods illustrated in the Stanford University cs193p Lecture 14 (the Photomania app). It uses a UITableViewController subclass that implements the NSFetchedResultsController delegates, and of course the table updates automatically as results are fetched.

Everything works but the UI blocks when the Document is populated with data, because it occurs in the Main thread (which is the document’s managedObjectContext). I’m already downloading the data in a background thread, this is just the code that actually populates the NSManagedObjects that is causing the blocking. The lecture alludes to using the NSManagedObjectContext’s Parent context in order to load up the Document in the background and then “refetch” the data in the main thread to populate the table. I almost have things working (I think) except I often get double entries in my table. It seems like the sort of thing [self.tableView beginUpdates] / [self.tableView endUpdates] would resolve, but because I’m doing the NSManagedObjectContext save in the background context I don’t know where I would put it.

I may also be going about this the entirely wrong way. 🙂 In any event, here is the relevant code:

NSManagedObjectContext *backgroundContext;
backgroundContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
// document is my UIManagedDocument
backgroundContext.parentContext = document.managedObjectContext; 

[backgroundContext performBlockAndWait:^{             
     // Do stuff here to populate the document.             
     [backgroundContext save:nil];
}];
  • 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-04T08:41:58+00:00Added an answer on June 4, 2026 at 8:41 am

    Well, not sure why, but this resolved my issue: https://stackoverflow.com/a/9451450/314051. Specifically, right before the [backgroundContext save]:

    NSSet *inserts = [backgroundContext insertedObjects]; 
    [backgroundContext obtainPermanentIDsForObjects:[inserts allObjects] error:&error]; 
    

    I’ll need to do some research to understand exactly why. Thanks for the suggestions, which helped me determine this wasn’t a UI issue.

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

Sidebar

Related Questions

I feel like I've read a question similar to this but I can't find
I feel like this is a very noob question.. but I just can't get
I feel like this is a stupid question, but I can't think of a
I feel like the problem is extremely apparent. I'm working on an issue with
I feel like this may be a dumb question, but it's late and my
I feel like the answer to this question is really simple, but I really
I feel like this must be very simple, but for some reason I am
I feel like this is a really simple question, but I need help figuring
I feel like I am missing something very simple here, but this is the
I feel like this is a rather simple question, but I can't seem to

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.