You must register your default values before attempting to access the value stored in NSUserDefaults. You can do this in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions .
Registration of default settings is quick, so there is no need to optimize this. Just do it when you start the application.
I save my user IDs in plist and register the contents of this list, for example:
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"DefaultUserDefaults" ofType:@"plist"]]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
If you register your default values like this, you don’t have to worry about overwriting user-supplied values. NSUserdefaults uses "domains" where it stores its values. If you register your default values, they are saved in the registration domain. If the user saves the value, these values are stored in the application domain.
If you try to get a value from NSUserdefaults, then see if this value is present in the application domain, and if not, it takes a value from the registration domain.
Edit:

you will get access to these values (or, better, the values that are stored in your nsuserdefaults, and those that are backup if there are no values provided by the user):
NSInteger minutesToWait = [[NSUserDefaults standardUserDefaults] integerForKey:@"MinutesToWait"; NSString *urlString = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultURLStr"];
Plist is just another NSDictionary representation with keys and values. The key is the same key that you use to access user identifiers, and the value is your default value. Pretty straight forward.
It doesn't matter how you create the dictionary. You can do this in code too.
source share