views:

1735

answers:

4

hi all

i'm wondering what's the best method to save and load data in a iphone application.

i'm trying to save strings into a text file or something like that and load them into a table view, so that the first entry in the text file is the first row in the table view and so on... somebody got an idea how I could realize that?

thanks in advance.
sean

+1  A: 

Have a look at the Core Data Framework for the iPhone SDK.

willcodejavaforfood
A: 

If your data is relatively small and does not have complex internal dependencies you can also store it in plist format (See Property list programming guide)

Vladimir
A: 

Depending on the size and complexity of the dataset you can use Core Data or a property list. For Core Data see the examples mentioned in the documentation (look for NSManagedObjectContext class).

For property lists use [NSKeyedArchiver archiveRootObject:myArray toFile:path] to save an array to disk.

The folder to store the file at can be determined with:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
Diederik Hoogenboom
A: 

There are basically three methods for saving data:

  • Use File Manager to save the file to the file system. (But in your case, you should not do that) It's useful for large images files only.
  • Use Sqlite to save your data into a relational database.
  • Use Core Data Framework to save all your data.

In your case, you should definitely learn how to use Core Data, it's hard at the first time, but it is really comfortable later on. There is as well the NSFetchedResultsController to handle the loading into TableView.

Most of the utility applications use Core Data to save data (Todo lists, etc..). The link to Core Data has been posted by willcodejavaforfood.

sfa