save and load data (iphone sdk)

后端 未结 4 1982
深忆病人
深忆病人 2021-01-28 14:51

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

相关标签:
4条回答
  • 2021-01-28 15:36

    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];
    
    0 讨论(0)
  • 2021-01-28 15:51

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

    0 讨论(0)
  • 2021-01-28 15:52

    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)

    0 讨论(0)
  • 2021-01-28 15:54

    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.

    0 讨论(0)
提交回复
热议问题