How to Save the Contents of an Array to the iPhone’s Filesystem

Matthew Campbell, April 16th, 2009

iStock_000007380486XSmall.jpgHere is one easy way to save data in your iPhone apps.

If you are using an array, say a list of strings, you can easily save that information to the documents directory of your app. In this example, we are going to create an array, fill it with values and then save the contents of the array to the documents directory.

Then, as we are going to stop the program and put in code that will retrieve the array from the filesystem. Finally, to prove that it all worked we will use an alert box to inform the user of what is in the array that we stored.

First, in the applicationDidFinishLaunching method put in this code:

Now, your information has been saved to the iPhone’s file system in the documents directory of your app. Here is how you would retrieve the information that you saved:

That is it – a quick and easy way to save information on the iPhone!

[...] week, I showed you how you can use NSMutableArray to save data to the iPhone’s filesystem and then retrieve the contents the next time the app is used. It [...]

  • Hours of videos, demos & screen casts
  • SOURCE CODE
  • Detailed HANDS-ON Exercises
  • Much Much Much More
  • UIKit
  • Objective-C
  • Core Data
  • More!
  • Learn How To Make An iPhone App right now using my proven system.

    PS: Tons of us are having a blast living off our own code, join us now. Click here to get all the details.