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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:58:15+00:00 2026-06-11T18:58:15+00:00

I have a Mac document-based app, using NSPersistentDocument for the document model. When new

  • 0

I have a Mac document-based app, using NSPersistentDocument for the document model.

When new document is created, the app adds some default data (several sport objects and user data) to the document in the initiWithType method.

- (id)initWithType:(NSString *)typeName error:(NSError **)outError {
self = [super initWithType:typeName error:outError];

NSManagedObjectContext *managedObjectContext = [self managedObjectContext];

[[SportManagement sharedManager] addDefaultSports:managedObjectContext];
[[UserManagement sharedManager] addDefaultUser:managedObjectContext];

[managedObjectContext processPendingChanges];

return self;

}

The app has an import function that imports data from some hardware, which runs in a thread, which I set up as follows (managedObjectContext is that of the NSPersistentDocument):

dispatch_async(dispatch_get_global_queue(0, 0), ^ {

    NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSConfinementConcurrencyType];
    [moc setPersistentStoreCoordinator:[managedObjectContext persistentStoreCoordinator]];

Data is imported from the hardware into a number of NSManagedDataObject items. Each ManagedObject has a ‘Sport’ field, which needs to be populated with one of the sport objects created when the document was created.

However, none of the sport objects that were added in the - (id)initWithType:(NSString *)typeName error:(NSError **)outError exist in the new ManagedObjectContext in the thread (moc).

If I run the app, create a new document, then let the app sit idle for a minute-or-so, then try the import, then the Sport objects DO exist in the thread Managed Object Context.

How do I sync the new ManagedObjectContext in the thread with the main one from the NSPersistantDocument?

I’ve tried: [managedObjectContext processPendingChanges]; and [managedObjectContext setStalenessInterval];, but neither seem the solve this problem.

Interestingly, this doesn’t appear to happen in Mac OS X 10.8, only in 10.7

  • 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-11T18:58:16+00:00Added an answer on June 11, 2026 at 6:58 pm

    Setup your “main” MOC to receive NSManagedObjectContextDidSaveNotification notifications, and merge the changes when the background MOC saves with -mergeChangesFromContextDidSaveNotification:.

    EDIT

    OK, it looks like you have made your changes in the MOC, but it is just a scratchpad. Until the data is actually saved to the persistent store, the persistent store does not know about the new data changes.

    Thus, when you create your other MOC and connect it to the PSC, it does not know about those changes.

    You can tell when autosave kicks in, because “after a while” it works.

    I would try a manual save of the document after you create the initial content.

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

Sidebar

Related Questions

I have a graphics-related Document-based Mac App. My app's Documents may have multiple pages.
I have a document-based Core Data application (running on Mac OS X 10.5 and
I have a Cocoa, Document-based Mac OS X application. One feature that I have
I have created a Mac app and need to place a shadow behind the
I'm new to Mac programming and I'm working on a document-based application. My NSDocument
I have created some JavaScript files and they run well from my Mac OS
I have a straightforward NSDocument -based Mac OS X app in which I am
I'm writing a new document-based cross-platform chemistry application (Win, Mac, Unix), which saves files
I have a Mac (not document) app, that uses CoreData. When launching the app,
I am new in mac os. I have one Mac book pro. I am

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.