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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:39:37+00:00 2026-05-12T19:39:37+00:00

I am working on an application that will perform a search against an online

  • 0

I am working on an application that will perform a search against an online service and generate many Result objects. A Result object is an NSManagedObject, initialized as required by associating it with an NSManagedObjectContext.

Users should be able to select a “Result” and save it as a “Favorite”. In the application this is as simple as associating the Result entity with a new Favorite entity and saving the context.

The problem is that every single Result in the context of course gets saved to the database along with the one I want Favorited.

I’ve seen many examples of using multiple NSManagedObjectContext instances to manage various creation and persistence situations. All of them seem to revolve around the idea of creating new instances with one Context and then merging them on save into another context for the sake of avoiding another FetchRequest execution. These examples don’t solve the problem as they still lead to every Result entity being saved.

Anyone have any suggestions? I’m totally tapped out on this.

  • 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-12T19:39:37+00:00Added an answer on May 12, 2026 at 7:39 pm

    You should use a different context for each object. Using a separate managed object context allows you to work as follows. When the user selects its favorite object, you just discard the contexts related to the remaining result objects. No need to merge changes etc. There is basically a tradeoff. You end up managing (creating/discarding) several contexts, but then you accomplish your goal easily. Otherwise, you can still do this using just a single context. However, you have to explicitly insert or delete each object as shown in the following code snippets.

    Try this. Only for the favorite object you want to save, do the following:

    [managedObjectContext insertObject:theFavorite];
    

    For each of the other result objects do this instead:

    [managedObjectContext deleteObject:aResult];
    

    then save as usual

    NSError *error = nil
    if (![managedObjectContext save:&error]) {
       // Handle error
    
    }
    

    This will save ONLY your selected, favorite object.

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

Sidebar

Related Questions

I am working on the developement of a application that will perform online backup
We are currently working on an application that will use a WCF service. The
I am working on a GUI application that will be used to perform manual
I am working on an application that will be used as an extensible framework
I'm working on an application that will have attachments, and I would like to
I am working on web application that will use PHP & MySQL. Application will
I am currently working on an application that will retrieve other users' locations based
I'm working on my first application that will use entity framework. I've got a
I'm working on a web application that will return a variable set of modules
I am working on an django application that will return what historically was a

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.