views:

176

answers:

1

I want to write a small bit of data from my app to the iphone so I can load it 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

+4  A: 

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"

Vladimir
Thank you Vladimir, the documents folder will probably be best, its only small so it would be good to have it get backed up by iTunes. Much appreciated.
fuzzygoat