0

I'm working on an app for ios6 which is using core data. Some time when my app crashes the data got inconsistent and some time when I terminate the app. I'm save the context each time I make change in the data and 'saveContext' is also called in 'applicationWillTerminate:'. Any help in this regard.

Afnan
  • 888
  • 1
  • 13
  • 37
  • What do you mean by "inconsistent?". If your app crashes or you stop it from Xcode or kill it from the multitasking bar, it won't get `applicationWillTerminate:`. – jrturton Dec 03 '12 at 06:59
  • 1
    Related: http://stackoverflow.com/questions/7818045/applicationwillterminate-when-is-it-called-and-when-not – jrturton Dec 03 '12 at 07:00
  • Yes, I got your point. How can I prevent the data from being inconsistant, I mean I made some changes in core data and save the context and if I stop the app from xcode; next time I run the app, I don't get the data I saved before stopping. – Afnan Dec 03 '12 at 07:06
  • Then you didn't save it. – jrturton Dec 03 '12 at 07:09
  • I save the context each time I change the data. I didn't get you point; Can you explain? – Afnan Dec 03 '12 at 07:11
  • If you'd saved it, it would be there when you restarted. You're either removing or replacing the database on startup, or you're not saving the changes properly, or you're not displaying them properly, but there isn't enough information in your question to say either way. – jrturton Dec 03 '12 at 07:14
  • When you stop the app in Xcode, you're basically crashing the app. It's not the same thing as the normal lifecycle you see on a device when a user switches away to another app. In some cases, hitting the home button in the Sim before you hit Stop can mitigate this. – Hunter Dec 04 '12 at 01:39

1 Answers1

0

Put a breakpoint at the line where you save the data, or use NSLog. Then reproduce your crash scenario. Most likely your save code was never called.

If still data is missing, examine your database by using the sqlite3 command line tool, or the Firefox plugin to view SQLite databases. Most likely you will find the data in the physical database - which implies you have a problem retrieving and displaying the data, not saving it.

If you still have missing data - congratulations! You have transcended the space-time continuum and entered a new dimension of reality.

Mundi
  • 79,884
  • 17
  • 117
  • 140