This question already has an answer here:
-
What is the use of -[NSUserDefaults registerDefaults:]?
5 answers
When i set registerDefaults in application:didFinishLaunchingWithOptions:
i set the default values for the NSUserDefaults throught the app.
NSMutableDictionary *defaultsDictionary = [@{@"userHasLoggedInOnce":@NO, @"firstTimeOpeningApp":@YES} mutableCopy];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDict];
[[NSUserDefaults standardUserDefaults] synchronize];
How does registerDefaults store that it has set these values only once, since its called every time on app start? Is it an own value thats also set as a standardUserDefaults value? If so, is it possible to reset the default values?
Register user defaults sets default values, for the keys. So when the application starts for the first time, you won't get nil, 0 or false and then have to test a lot of times through your code if that's the case. Instead you set something like "Welcome".
Edit:
The contents of the registration domain are not written to disk; you need to call this method each time your application starts. You can place a plist file in the application's Resources directory and call registerDefaults: with the contents that you read in from that file. (Source)
As the comment explained, calling registerUserDefaults doesn't override the savedValues, so you can safely call it each time the application launches. You can add a reset button, where you override the saved values by the user, with the values in your plist (defaults).