views:

28

answers:

1

i want to save NSMutableArray or NSDictionary to save as file and close application. then reopen application and read some data from that file to use. is it possible?

+2  A: 

To write in file

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:FILE_NAME];

[myArray writeToFile:filePath atomically:TRUE];

To read from file

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:FILE_NAME];

myArray = [NSArray arrayWithContentsOfFile:filePath];

myArray will be nil if file is not present. And NSDictionary has similar methods. Please cheek the reference for the details of these functions.

taskinoor
thanks taskinoor , let me try.
RAGOpoR