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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:59:02+00:00 2026-05-10T14:59:02+00:00

I am working on a cocoa software and in order to keep the GUI

  • 0

I am working on a cocoa software and in order to keep the GUI responsive during a massive data import (Core Data) I need to run the import outside the main thread.

Is it safe to access those objects even if I created them in the main thread without using locks if I don’t explicitly access those objects while the thread is running.

  • 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. 2026-05-10T14:59:02+00:00Added an answer on May 10, 2026 at 2:59 pm

    With Core Data, you should have a separate managed object context to use for your import thread, connected to the same coordinator and persistent store. You cannot simply throw objects created in a context used by the main thread into another thread and expect them to work. Furthermore, you cannot do your own locking for this; you must at minimum lock the managed object context the objects are in, as appropriate. But if those objects are bound to by your views a controls, there are no ‘hooks’ that you can add that locking of the context to.

    There’s no free lunch.

    Ben Trumbull explains some of the reasons why you need to use a separate context, and why ‘just reading’ isn’t as simple or as safe as you might think, in this great post from late 2004 on the webobjects-dev list. (The whole thread is great.) He’s discussing the Enterprise Objects Framework and WebObjects, but his advice is fully applicable to Core Data as well. Just replace ‘EC’ with ‘NSManagedObjectContext’ and ‘EOF’ with ‘Core Data’ in the meat of his message.

    The solution to the problem of sharing data between threads in Core Data, like the Enterprise Objects Framework before it, is ‘don’t.’ If you’ve thought about it further and you really, honestly do have to share data between threads, then the solution is to keep independent object graphs in thread-isolated contexts, and use the information in the save notification from one context to tell the other context what to re-fetch. -[NSManagedObjectContext refreshObject:mergeChanges:] is specifically designed to support this use.

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

Sidebar

Related Questions

I'm working on a Cocoa Mac app where I need to display a window/view
I'm working on a Cocoa application, and I've run into a situation where I
I'm working through Cocoa Programming for Mac OS X (3rd ed) and in chapter
I've been learning Objective-C and Cocoa by working my way through the Hillegass book
Why is the following code (in cocoa) not working? NSString *extension = [fileName pathExtension];
I'm working with CoreData in Cocoa (not document-based). My problem is, that I want
I'm adding repeating events to a Cocoa app I'm working on. I have repeat
I'm learning objective-c, working through Aaron Hillegass' book Cocoa Programming for Mac OS X
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch

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.