Wednesday, July 28, 2010

Simple Serialization (Well, Archiving) on iOS: Filenames

I sometimes forget that the simulator is not a real device, though it sure does get you there about 99% of the time. So anyway, the filenames that I presented in this post do not work. But after looking around for 10 seconds, I found the answer:

NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [docsPath stringByAppendingPathComponent:@"somewhereInAppSandbox"];

Then you can just use 

[NSKeyedArchiver archiveRootObject:array toFile:filename];


[NSKeyedUnarchiver unarchiveObjectWithFile:filename];

as I suggested in the other post. Obviously for anything serious you would use CoreData or Sqlite.

No comments: