Question

I have a simple question about one of my iPhone applications.

I have a few global counters that store numbers from 0 up to 13, and once the program is terminated (click stop on simulator) and reopened in debug mode, the counters still have the same information as the previous run. Where in my code should I reset all my counters? Ideally I only want them to be reset if you terminate the program from the iPhone multitasking feature (double tap home button and exit program).

There isn't any code that is necessary to see, and I don't want to have a button that you can press to reset the counters either.

Any suggestions?

Was it helpful?

Solution

Assume the counters are persisted (stored somewhere when your app exits). There are a couple of ways you can go about it:

You can set the counters in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

or reset them to 0 in

- (void)applicationWillTerminate:(UIApplication *)application

Those two functions are found in AppDelegate.m

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top