The NSUserDefaults Class allows you to save settings of your app so that when the user closes the app or perhaps reboots their iOS device, the settings you set are retained. A quick example could be a maps app that lets you set it to show distances in Miles or Kilometers.
Before I continue, I want to point out that if you want to share settings across devices then you need to look at storing preferences in iCloud.
In todays tutorial I want to show a quick demonstration of how NSUserDefaults works and how you create the object as well as save data. I will also show you how to retrieve the data so that your app can load up with the settings the user selected.
Various types of data can be stored in NSUserDefaults which includes NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. Typically you would wrap a UIImage in to NSData to store in NSUserDefaults. Of course, you can also use other options to store data such as CoreData, but NSUserDefaults is a quick and simple way to store small amounts of data with just a few lines of code.
Lets begin by creating a new Single View application in Xcode. We then need to add a few things to the storyboard. Although you can follow this tutorial step by step, perhaps you could also experiment with your own ideas. The storyboard below has two views. The standard View Controller on the left that is set up when you create a Single View App. The second is a Table View Controller. I chose a Table View Controller because this is how I typically see settings views arranged. Of course, it isn’t essential that you use a Table View Controller for a settings view.