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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:47:38+00:00 2026-05-13T12:47:38+00:00

In the generated code for core data stack, a save on managedObjectContext is called

  • 0

In the generated code for core data stack, a save on managedObjectContext is called in applicationWillTerminate method. This is to take care of all unsaved objects in the context before exit.

This has an unwanted side effect of saving any temporary objects as well. (This problem is visible in apple sample codes as well. If you click on + to add new Recipe in Recipe sample code, and then press Home button to terminate the app, a half done Recipe object is visible when you start the app next time).

What is the preferred design pattern for handling this issue? I could think of the following.

  1. Use a different scratchpad managedObjectContext for temporary objects and when you decide to really Save, then push a copy in the main managedObjectContext. Call save only on main managedObjectContext in applicationWillTerminate. (Is there any easy and fast way to move an object from one managedObjectContext to another apart from creating a copy manually in the new context?)
  2. Remove save from applicationWillTerminate, but ensure that all Objects are saved immediately after changes are made. (This may not easy all the time, I have a Tabbed application, a user may have initiated editing operations at the same time).

Let me know if there is a better way to handle 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-13T12:47:38+00:00Added an answer on May 13, 2026 at 12:47 pm

    Solution 1 does not entail copying objects.
    The pattern is illustrated in the CoreDataBooks example. You can create new objects in a second context, then fault them into the main context either directly (using objectWithID:) or (as shown and explained in the example) by observing NSManagedObjectContextObjectsDidChangeNotification and merging the changes into your main context.

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

Sidebar

Related Questions

This is my GeneratedCode for Core data, automatically generated by xCode Editor. #import <Foundation/Foundation.h>
I have been given some generated code which looks like so: <form id=form1 method=post
I am writing an iPhone app which uses core data for storage. All of
Ok, I am getting better at this Core Data stuff, but I've got a
I have a problem with Core Data. The problem happens with this scenario :
The code generated by Xcode when creating a navigation based application which uses core
Im using xsd:unique in an xsd generated code. How do I get an item
What are the differences in compilability or generated code (if any) between the following
Quasi-quotes allow generating AST code during compilations, but it inserts generated code at the
I have some auto-generated HTML code. When I add a float:left; on the shared

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.