Archiving - Data not persisting


I have implemented the code in this chapter and my Possession instances persist when I terminate the application by hitting the home button, but when I terminate the application by deleting the app by double clicking the home button and then x’ing out the app and then relaunch, the Possession instances are gone. What may I be doing incorrectly?


Which means you didn’t archive the data to disk. Check the code where you load and save data to disk. Check the spellings.


I know your question was posted over 2 years ago, but I want to add something - and I hope someone can enlighten me as to what’s happening. Here’s my question:
I’ve used the code in the first edition to create persistent data, and it works wonderfully. The code is in one app that is already in the App Store, and I have it in another app that I’m developing. After more than 8 months of carefully documenting and testing both apps, I can state with complete certainty that the data disappears under certain conditions. I check to see that my “Possessions” are still there when I go to bed. I click the Home button so the app goes into the background. I then plug in my iPhone 5 to charge it overnight. The very next morning I check to ensure the “Possessions” are still there, and 99.9% of the time they are. However, about every two months, they mysteriously disappear. One time they disappeared in both my apps during the same overnight period, but usually they disappear from one app at a time, on different nights. Obviously, it’s not the code. Does anyone have any ideas what’s happening? (Maybe a power surge during the night causes the problem?) Incidentally, one other user also reported the same problem.

I’m thinking of modifying the apps to save the data in NSUserDefaults.

Any thought would be appreciated.


Do you know for sure that the data is being saved persistently during the phase the application goes through before it goes into the background. You can easily test for this by disabling the runs-in-the-background mode.


Hi ibex10:
Sorry it took so long to answer your post - I missed it, and didn’t see it until today (8/8/13).
The answer to your question is, no, I’m not sure. However, I’ve lost confidence in using NSKeyedArchiver and saving data to the sandbox. I’m in the process of changing my code to use NSUserDefaults, since I’m saving only a small amount of data.