Initial values for NSUserDefaults aka first run values

This content has 9 years. Please, read this page keeping its age in your mind.

If you want initial values to NSUserDefaults, you can use registerDefaults method.

Consider that the first time you access the property with some key name the value will be either nil for objects, false for booleans or 0 for numbers.

So, prepare a plist file in your bundle that contains the default preferences and then use that plist to register the defaults.

Then in appDelegate.m add:

<code>NSString *defaultPrefsFile = [[NSBundle mainBundle] pathForResource:@"defaultPrefs" ofType:@"plist"];
NSDictionary *defaultPreferences = [NSDictionary dictionaryWithContentsOfFile:defaultPrefsFile];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultPreferences];</code>

Credits to Mr. Ole Begemann and John Topley