0

I create an application that use two xcdatamodel file to save data. Everything works fine, the data can save and load successfully. But it is weird that when I reboot the device, data in one model is lost and another is still exists. It usually happens on iOS 5.0 and device is locked with passcode.

Is there anybody have this problem too? Please help me about this. Thanks.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
stevensei
  • 21
  • 1

1 Answers1

0

Sounds like one or more of your managed object contexts being saved. One way this can happen is if you have a context that's a child of another context. Sending a save message to the child context just adds the modified objects to the parent, but it doesn't get saved to your file. To actually save the data to a file, you have to make sure that you save your root context.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • Thank for your quick response, Caleb. But it is really weird, although I delete until there is only one model, the records are still gone. I relaunch the application many times, it still has data. But when I reboot with the application running, the data is gone. – stevensei May 14 '12 at 10:24
  • 1
    I'm with Caleb, in that you are probably not saving properly. When you "quit" the app, are you just multitasking it out, or are you specifically exiting the application (double-click power button, long press app, click on X to exit)? – Jody Hagins May 15 '12 at 01:15
  • Hi Jody, I relaunch the application by double click power-button, long press app then click X to exit. And after relaunch, the data can load properly, so it can sure that the data is saved properly, right? The data is gone whenever I reboot the device. – stevensei May 15 '12 at 07:12