save and load data (iphone sdk)

落花浮王杯 提交于 2019-12-20 07:17:56

问题


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:


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.




回答2:


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




回答3:


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)




回答4:


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];


来源:https://stackoverflow.com/questions/2206013/save-and-load-data-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!