Question

which is the proper method to set NSUserdefaults after launching of the app, not the first launch really, ANY launch. I need to define some flags.

viedDidLoad or viewDidAppear? I'm not sure and I want to produce clean code.

Also, which one t set the variables free? applicationWillTerminate? I dont want to delete the vars when like a phone call arrives, but when the user closes it by clicking the homebutton. thanks in advance

Was it helpful?

Solution

which is the proper method to set NSUserdefaults after launching of the app, not the first launch really, ANY launch. I need to define some flags.

That sounds like a total misuse of NSUserDefaults (especially if your goal is to "produce clean code"). NSUserDefaults can certainly be used for globals, but its purpose is to persist values. Resetting those value on each launch is just the opposite of what NSUserDefaults is for.

If you are trying to set some variables on launch, then use variables. You can set them in applicationDidFinishLaunching... in your app delegate, and make them available from there (every object can see the app delegate).

Also, which one t set the variables free? applicationWillTerminate?

There is no need to free anything. If you use real variables they will go out of existence when the app terminates (and you will give them their initial values when the app launches, as I've already explained).

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