Re: Accessing NSKeyedArchiver's archivedDataWithRootObject by name
Re: Accessing NSKeyedArchiver's archivedDataWithRootObject by name
- Subject: Re: Accessing NSKeyedArchiver's archivedDataWithRootObject by name
- From: "Michael Ash" <email@hidden>
- Date: Tue, 9 Dec 2008 18:03:56 -0500
On Tue, Dec 9, 2008 at 1:17 PM, Jim Turner <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden