views:

89

answers:

1

I'm using something like the code below to save an NSDictionary of objects to the device. Is there a way to open this archive, drill down into the Dictionary items that it contains and, ideally, edit the data? My guess is no, not reliably, as the optimization done when saving makes the archive difficult to interpret...at least it appears that way when opened with something like Property List Editor. For instance, if some of my objects share a similar NSString it appears that said NSString is only archived once...altering the structure of the NSDictionary from what I had been expecting.

- (BOOL)writeDataToFile {
 NSMutableData *data = [[NSMutableData alloc] init];
 NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
 [archiver encodeObject:myDictionary forKey:kDataKey];
 [archiver encodeInteger:kDataFileVersion forKey:kDataVersionKey];
 [archiver finishEncoding];
 BOOL success = [data writeToFile:[self dataFilePath] atomically:YES];
 [archiver release];
 [data release];
 return success;
}
+1  A: 

The real question is "should you?" ... probably not.

Sure, you could parse the file format, but that format is an implementation detail that could change and it's just not worth it.

Why are you trying to do this? Are you trying to make incremental edits a la Core Data + sqlite? Would just plain old sqlite itself solve your issue?

Joshua Nozzi
I was just curious if maybe I was overlooking, or wasn't aware, of some *thing* or some *tool* that could parse these files. Why? Mostly to test how an application responded to different types of data in the archive. Nothing related to CD or SQLite.
Meltemi