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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:55:24+00:00 2026-05-27T18:55:24+00:00

Happy New year. Iam working with a app where data is saved by using

  • 0

Happy New year.

Iam working with a app where data is saved by using core data. The app contains a calendar module and the user is allowed to skip back/forth between dates by two buttons(nextDay, previousDay). Each day contains som information which I fetch from a webservice, and therefore I would like to fetch a large part of the data(the next 14 days) in the background while the users uses the calendar.

So here is my approach:

The data of the first day is fetched by the main thread and save to the persistent store and presented to the user. Then a NSThread is started in the background with a new nsmanagedcontext fetching data and when the all data is fetched it is saved to the persistent store.

However while this background thread is running, the user has the option to skip to the next day or the previous day, and if there is no data the main thread will fetch the data and save it to the persistent store. This presents the possibility of both threads fetching the same data and saving it to the persistent store. But as I understood this approach should not be a problem as I use a new nsmanangedcontext for the background thread.

But sometimes I get the following error The operation couldn’t be completed. (Cocoa error 133020.) and then the main thread cannot save to the persistent store.

I have tried using only one nsmanagedcontext shared between the threads, but this sometime causes one of the threads to stop and never move on.

I have spent a lot of hours reading different forums/blogs and hope anyone can help or guide me in the right direction.

regards

SOLVED WITH HELP:
The error i was getting was due to errors during merging when saving to my persistent store. I was able to solved it by changing the merging policy when saving. The following snippet shows my method for init of nsmanagedcontext. Where the bold shows the setting of policy. I can do this because the data which i am fetching is the same, no matter if it is the main thread or the background thread.

- (NSManagedObjectContext *)managedObjectContext
{
    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil)
    {
        __managedObjectContext = [[NSManagedObjectContext alloc] init];
        [__managedObjectContext setPersistentStoreCoordinator:coordinator];
          **[__managedObjectContext setMergePolicy:NSOverwriteMergePolicy];**
    }
    return __managedObjectContext;
}
  • 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-27T18:55:24+00:00Added an answer on May 27, 2026 at 6:55 pm

    According to http://developer.apple.com/library/ios/#documentation/cocoa/Reference/CoreDataFramework/Miscellaneous/CoreData_Constants/Reference/reference.html your error code represents a NSManagedObjectMergeError.

    Since your always fetching the same data, I’m assuming it should be the same whether you got it from the background thread or your main thread, so you should be able to change your merging policy from it’s default NSErrorMergePolicy to NSOverwriteMergePolicy which will overwrite any conflicted object with the new data (again, assuming they are the same, this wouldn’t be a problem).

    You can find more on merge policies here: http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSMergePolicy_Class/Reference/Reference.html#/

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

Sidebar

Related Questions

Happy New Year. I have a bunch of SOAP Web Services. They all have
Happy new year to you all! I am plotting some graphs and would like
Happy New Year 2010 everyone :) Just getting back into the Flash groove, and
Hi there (& Happy New Year!) Are there some examples on how I can
Happy New Year everybody,now I am trying to develop my own bot( web crawler
First of all-many season-greetings and a happy new year to all of you! Have
I am new to the core data and am loving it so far, I
Hi guys and happy new year(2010). I'm a kind of novice in WPF's ListView.
hope you all had a happy new year. So, my question is, what's the
Hello and Happy New Year all! While thinking about new project I decided 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.