iOS NSUserDefaultsNSUserDefaults is one of simplest ways to store your configuration/settings of your iPhone/iPad application. You don't have to create a plist or work with the file system, it encapsulates all of that.

The value that is to be stored can be instance of  NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. Internally this API knows how to serialize/deserialize the instance.

<!>

  1. // get the handle
  2. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  3.  
  4. NSString *key = @"username";
  5. NSString *value = @"john";
  6.  
  7. // set the value
  8. [defaults setObject:value forKey:key];
  9.  
  10. // save it
  11. [defaults synchronize];
  12.  
  13. // Get the result
  14. NSString *retrievedValue = [defaults stringForKey:key];