views:

43

answers:

1

I'm using NSKeyedArchiver to write out an NSDictionary of my app's data to the filesystem.

NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:myAppsDictionary forKey:kDataKey];
[archiver finishEncoding];
BOOL success = [data writeToFile:[self dataFilePath] atomically:YES];

Is there a simple way to attach a version number to this datafile without adding an object to the NSDictionary itself? Could I just insert a line before finishEncoding that would hold a key/value of the version number? Would encodeInt32:forKey: work? Or, is there a more Cocoa friendly way?

+2  A: 

I believe your proposal is fine.

You might find this Apple document helpful: http://bit.ly/2T2cSg

Excerpt: "You may just encode a “version” integer or string with some key or in some rare cases you may want a dictionary object full of goodies."

nall