How to save data in iOS

There are several ways to save and retrieve data for persistent storage (i.e. when you close your app and open it again). This is the easiest one I can think of: NSUserDefaults.

Here’s an example that saves a text field from an IBOutlet. We’re saving both a string and an integer. We can use this in any IBAction like a “save button”, via the ViewDidUnload method in your View Controller, or via methods in your AppDelegate.m file:

The important thing to notice is that [defaults synchronize]; does the actual saving. This is not needed when you load the data (see next post). You can save as many options as you like, just remember which keys you’ve used so that you can retrieve those values later.

You can save the following types of data:
NSData, NSString, NSNumber, NSDate, NSArray, and NSDictionary.

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at and

Add your voice!