Write simple data to iphone sandbox?
I want to write a small bit of data from my app to the iphone so I can load i开发者_StackOverflowt when the app next starts. I am going to write the data using NSCoding, but I don't know what I should be specifying as a path. I understand I would write the data to the application sandbox, just not sure how to specify that.
gary
Several paths are available: Documents folder - its contents persist between application launches and is backuped by iTunes. To get path to it use:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileInDoc = [documentsDirectory stringByAppendingPathComponent:fileName];
Caches folder - almost same, but contents is not backuped by iTunes.
For more information see Commonly Used Directories and Getting Paths to Application Directories in "iPhone Application Programming Guide"
精彩评论