NSUserDefaults Archives

How to load data in iOS

Here’s how you load data you’ve previously saved with NSUserDefaults. Since you only load data once I’d put this in the AppDelegate.m file (as applicationDidFinishLaunching) or in ViewDidLoad if you have a single view application: // let’s load our data if there is any NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; int theNumber = [defaults integerForKey:@”theNumber”]; NSString […]

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 […]