Breaking News
Home / iOS / iOS Snippets / Using NSUserDefaults to store Settings in iOS

Using NSUserDefaults to store Settings in iOS

iOS NSUserDefaults´╗┐NSUserDefaults 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];
  4. NSString *key = @"username";
  5. NSString *value = @"john";
  7. // set the value
  8. [defaults setObject:value forKey:key];
  10. // save it
  11. [defaults synchronize];
  13. // Get the result
  14. NSString *retrievedValue = [defaults stringForKey:key];

Check Also

EKCalendar – That account does not allow calendars to be added or removed

Usecase When I am trying to create a new Calendar programmatically using the EventKit API …

Advertisment ad adsense adlogger