Does registerDefaults method set the default value and not the actual value
Yes. The value that you pass in the dictionary to registerDefaults:
is returned to you only when there is no specific value set for that key.
When you set the value @"1"
for the key @"test"
, you "hide" the default value registered in the registerDefaults:
call.
If you do this
[NSUserDefaults standardUserDefaults] registerDefaults:@{@"a":@"1", @"b":@"2"}, nil]];
[[NSUserDefaults standardUserDefaults] setObject:@"200" ForKey:@"b"]; // Override
and then request the values for keys @"a"
and @"b"
, you get the default value @"1"
for @"a"
and the specific value of @"200"
for @"b"
.