Re: [iPhone] NSKeyedArchiver with NSValue Objects
Re: [iPhone] NSKeyedArchiver with NSValue Objects
- Subject: Re: [iPhone] NSKeyedArchiver with NSValue Objects
- From: Quincey Morris <email@hidden>
- Date: Thu, 24 Dec 2009 12:47:28 -0800
On Dec 24, 2009, at 09:59, Henry McGilton (Boulevardier) wrote:
> I bashed into a problem with NSKeyedArchiver trying to encode
> NSValue objects.
>
> I am using NSValue to wrap up CGPoint and CGSize structures, then
> doing an encodeObject: forKey: to encode the NSValue.
>
> I get this message:
>
> [NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs'
>
> I poked around in CocoaBuilder and Google for some definitive answers, but
> the discussions appear to be mostly froth. This seems a little strange, as UIKit
> provides a bunch of NSValue additions to encode those CG structs, but the
> NSKeyedArchiver can't encode them. And the message is somewhat misleading:
> I'm encoding the NSValue object, not the structure . . . I'm assuming (I know, one
> should never assume) that the NSValue object is invoking that encodeValueOfObjCType:at:
> message . . .
NSValue objects are not in suitable for archiving because there's no API contract that says they'll deal with byte ordering issues for you. (And, in fact, they couldn't, for structs in general.)
If you're dealing with NSPoint and NSSize, you can use -[NSKeyedArchiver encodePoint/Size: forKey:], but you're crossing framework boundaries (a little bit) with CGPoint and CGSize, so you have an extra step. Either convert to NSPoint/NSSize and use the matching NSKeyedArchiver method, or encode the two structure components as numbers.
_______________________________________________
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