The difference is that the first code fragment you register defaults that will be used when the user has not made any changes to the "property".
So, if you want to let let say say “property” with the key name “Welcome message”, you can instead of returning the nil property, insert the default message “Welcome first-time user”, which will be displayed when it has not been changed into the property.
This will simplify your logic because you do not need to write an if test to check if the property returns the nil property and then creates another message if that is the case.
NSString *greeting = [[NSUserDefaults standardUserDefaults] stringForKey:@"Greeting"]; if(greeting == nil) { NSLog(@"Welcome first-time user!"); }
The second piece of code you submitted is for setting the property to a different value. You will have different set methods (setString, setObject, setBoolean) for setting values depending on your program state in Userdefaults.
EDIT ----- Updated on request in the comments.
The first method is designed to register default values, as the name suggests. When you first access a property with some key name, the value will be either zero for objects, or false for boolean values, or 0 for numbers. Instead of doing a lot of tests and so on, so that if the values are not set in the program, and then do something "by default", for example, the example above, you can send your application with some predefined values for these keys.
A typical place to set registerDefaults is in the initializer method in appDelegate.
Then somewhere in your program you can set the values of these fields, then you use setObject, setString, setBoolean ... and for extraction you use stringForKey, objectForKey ...
Think of it as
RegisterDefaults is a constructor where you can provide reasonable values for an object, otherwise you will get some default values that I already wrote. Then, if you want to change the attributes of an object, you are NOT using the "constructor", but the set / get methods.