2

When saving and loading using NSCoder in XCode, I can't seem to save the application state and load it back.

What I'm trying to accomplish is to save the app state and then reload it every time I restart. In essence, continuing where I left off.

Does the ios Simulator wipe the environment clean every time?

If so, is there any way to get around this behaviour?

kfmfe04
  • 14,936
  • 14
  • 74
  • 140

1 Answers1

3

Does the ios Simulator wipe the environment clean every time?

No, it doesn't. You shouldn't have any trouble saving state and reloading it, provided you do it the right way in the first place. For example, people often have trouble because they try to write files inside the application bundle, but the application bundle is always read-only. Save your data somewhere else, such as the app's Documents folder, the defaults system, the Cache directory, etc.

Also, remember that your app's data will be deleted from the simulator if you delete the app, just as it's deleted from the device if you delete the app there. If you simply rebuild the app and run it without first deleting it from the simulator, any data you wrote previously should still be there.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • I am using NSKeyedArchiver to save the AppState. Should I be writing directly to a file somewhere instead? – kfmfe04 Oct 12 '14 at 17:45
  • NSKeyedArchiver only stores data into a NSData instance. If you want the data to persist, you'll obviously need to write that data into a file somewhere. – Caleb Oct 12 '14 at 17:47
  • ty - I will investigate the options you listed for writing to file – kfmfe04 Oct 12 '14 at 17:51