Thats great - I was thinking I had to save the settings I didnt want to expose to the user in a separate file, but this way is much handier.
Ive only created NSUserDefaults using the Settings.bundle (in the xml-editor), so Im not sure how to instantiate a NSUserDefault-object without it.
I know the syntax for instantiating is:
Code:
// Instantiate NSUsersDefaults:
NSUserDefaults *myUserDefaults = [NSUserDefaults standardUserDefaults];
// And the rest - getting and setting - we've already covered:
// Set:
[myUserDefaults setObject:@"felix" forKey:@"Username"];
// Get:
[[NSUserDefaults standardUserDefaults] stringForKey:@"Username"];
But where do I put the instantiation-code? Do I put it in the Delegate.h/m-files like this:
Code:
// myDelegate.h
// ----------------
@interface myDelegate : NSObject <UIApplicationDelegate, NSUserDefaults>
{
NSUserDefaults *myUserDefaults = [NSUserDefaults standardUserDefaults];
}
// myDelegate.m
// ----------------
@synthesize myUserDefaults;
But how do I go about setting the default-values for them? If I do that in the delegate-code each time the app starts, wouldnt I overwrite the settings from the last session with my initialization of the defaults? This is a bit onfusing..