views:

100

answers:

2

How do I store an NSMutableArray to Disk on an iPhone app for later retrieval?

+2  A: 

NSArray (as well as other property list objects) provides easy saving/loading to the file - using following methods:

+ (id)arrayWithContentsOfFile:(NSString *)aPath
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag

It might be useful to read Property List Programming Guide in Apple docs for more details.

Vladimir
+2  A: 

Use [NSKeyedArchiver archiveRootObject:myMutableArray toFile:path]

The folder to store the file at can be determined with:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
Diederik Hoogenboom