On Tue, Dec 9, 2008 at 1:17 PM, Jim Turner [EMAIL PROTECTED] wrote:
I have a situation where I'm archiving an array of objects via
NSKeyedArchiver's archivedDataWithRootObject: and later needing to set
a delegate on the NSKeyedUnarchiver that decodes it. The
documentation is a bit unclear on how one starts the unarchive process
when a NSKeyedUnarchiver is created on an archive where you don't
know, for certain, the keys it contains.
So my question... is this legitimate?
NSKeyedUnarchiver *_keyedUnarchiver = [[[NSKeyedUnarchiver alloc]
initForReadingWithData:archivedData] autorelease];
[_keyedUnarchiver setDelegate:self];
NSMutableArray *archivedArray = [_keyedUnarchiver decodeObjectForKey:@root];
[_keyedUnarchiver finishDecoding];
It works, but I always question things when I hard-code a string for
something. Will 'root' always be the key that represents the root
object?
If I could do something like [NSKeyedUnarchiver
unarchiveObjectWithData:delegate:], that would be better than perfect.
This is an interesting question. NSArchiver describes exactly how the
root object stuff works in terms of the rest, but NSKeyedArchiver
doesn't. I would file a bug, at least to get it documented.
However, one of the painful and pleasurable thing about stuff like
NSCoder is that it essentially has to remain forward and backward
compatible for eternity. An NSKeyedArchiver running on 10.7 must
produce an archive which can be read on 10.2. This sort of thing
presumably couldn't be changed without breaking 10.2 or some other
past OS, so uncomfortable as it may be, if it works today it ought to
keep working forever.
Mike
___
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 [EMAIL PROTECTED]