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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:26:20+00:00 2026-05-27T20:26:20+00:00

I have an operation in my app which requires a large, sometimes several second

  • 0

I have an operation in my app which requires a large, sometimes several second update with Core Data. Because I’d like to do more than just show a spinner, I’d like to display a progress bar to the end user. This presents some issues, however, because of Core Data’s insistence on running on the main thread. I have attempted to put Core Data on a background thread with dispatch_async with disastrous results. The problem is that UIKit also wants to run on the main thread and worse still, only does its updates after the current thread has ended. This results in the progress bar only being updated until after it has finished all its processing!

How can get the UI updated and safely update my data?

NSArray* items = [[response.data objectForKey:@"result"] objectForKey:@"items"];

NSManagedObjectContext* context = [RBGameItemController sharedInstance].managedObjectContext;

int itemCount = [items count];

for (int i = 0; i < itemCount; i++) {
    float progress = ((float)i/(float)itemCount)*0.95f;
    self.progressView.progress = 0.5f + progress; 

    id item = [items objectAtIndex:i];
    [GameItem gameItemFromDictionary:item inManagedObjectContext:context];
}

NSError* error = nil;
[context save:&error];
  • 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-27T20:26:20+00:00Added an answer on May 27, 2026 at 8:26 pm

    Core Data does not require working on the main thread, only that you have an NSManagedObjectContext for each separate thread. Create a new NSManagedObjectContext with the same backing store on a separate thread (using NSOperationQueue) and do the processing there. Once you save the NSManagedObjectContext from your alternate thread, your main thread’s context will pick up the changes from the backing store. To update your UI from the alternate thread, use

    - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;
    

    which is a method on NSObject. Good luck and comment if anything’s not clear.

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

Sidebar

Related Questions

In my app, I have a UITableViewController which loads calculated data from my Core
I have a simple operation like so: k + 1 What would be a
Using POSIX threads & C++, I have an Insert operation which can only be
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
I have a Django app with custom form fields, some of which have slow
I have a WPF 4 app which I want to enable drag and drop
In my app I have a map and when the user does any operation
I have an app which calls another process in a command window and that
I have an iOS app with a really nasty bug: an operation in my
I have an Android application which uses the NDK to execute a large amount

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.