[a encodeObject:p forKey:@"root"];

Does using:
[a encodeRootObject:p];

instead of the line above make it work as expected?

A good idea, but IIRC that did not work. In fact, I think it produced an archive that silently failed to be read back by the stock +[NSKeyedUnarchiver unarchiveObjectWithFile:] convenience method.

While the documentation for that method itself makes no mention of that fact, the documentation at http://developer.apple.com/ documentation/Cocoa/Conceptual/Archiving/Tasks/decoding.htm does say "NSKeyedUnarchiver requires that the object graph in the archive was encoded with one of NSKeyedArchiver’s convenience class methods, such as archiveRootObject:toFile:." I'm not sure offhand why this would be, and it is a bummer, but the "workaround" is to just do the unarchiving symmetrically to the archiving, that is read the file into an NSData and then unarchive that using - decodeObject (or -decodeObjectForKey: if you encode with your own root key(s) after all). I'll note that I haven't tested this myself again, but that seems to be what the documentation is saying.

You're quite right, one ordinarily just uses a symmetric set of methods to decode/encode the data. The problem I had was that I needed to use -[NSUnarchiver decodeClassName:asClassName:] for unarchiving a file previously encoded using the convenience method. Certainly it's possible to use the class method +[NSUnarchiver decodeClassName:asClassName:], but it seems silly to pollute the global archiver class table for a single file.

I've filed a documentation bug as radar://6440080

~Martin

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to