When to store app data?

Hi,

I’m using the storyboard API and saving data into a table in memory.   The question I have is:

When should I persist the table to a file (via JSON), is there a GLOBAL ‘app is exiting’ event I can trap or should I be writing out my data as it’s updated in every scene?

Ta!

I would suggest saving it every “logical” chance you get. That is, whenever the data makes a nice, complete set that you can use to re-load your applications state, that’s a good save data point (as opposed to halfway through levels, or halfway through editing settings, etc). Save it when your app is in a good, re-loadable state.

I’m not big on solely relying on saving at the application close event, just because I don’t trust that it will always fire off. If the user exits normally I believe it does, but not so sure if the app crashes (does it still get the event, or can it even deal with the save at that point / is the data corrupted too?), if the battery is removed, or other scenarios.

So I’d recommend saving while the saving is good (at logical points of course). You might lose a half level of data in a catastrophe, but it’s a lot easier than coding your loadData function to be able to handle loading a half done level as well.

I am currently trapping the applicationExit event and doing it there but yes it makes sense to save it off at known ‘safe’ places.

Ta

I would suggest saving it every “logical” chance you get. That is, whenever the data makes a nice, complete set that you can use to re-load your applications state, that’s a good save data point (as opposed to halfway through levels, or halfway through editing settings, etc). Save it when your app is in a good, re-loadable state.

I’m not big on solely relying on saving at the application close event, just because I don’t trust that it will always fire off. If the user exits normally I believe it does, but not so sure if the app crashes (does it still get the event, or can it even deal with the save at that point / is the data corrupted too?), if the battery is removed, or other scenarios.

So I’d recommend saving while the saving is good (at logical points of course). You might lose a half level of data in a catastrophe, but it’s a lot easier than coding your loadData function to be able to handle loading a half done level as well.

I am currently trapping the applicationExit event and doing it there but yes it makes sense to save it off at known ‘safe’ places.

Ta