save and load data (iphone sdk)

后端 未结 4 2084
深忆病人
深忆病人 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];
    

提交回复
热议问题