Re: How to archive structs like NSRect
Re: How to archive structs like NSRect
- Subject: Re: How to archive structs like NSRect
- From: Steve Christensen <email@hidden>
- Date: Mon, 12 Nov 2007 20:59:43 -0800
I'm coming in on the middle of this thread, so excuse me if I'm
repeating something already covered.
It seems like the issue isn't in encoding/decoding a NSDictionary,
but rather correctly handling the case where objects in the
dictionary contain a non-native representation of a struct, such as a
NSString created by calling NSStringFromRect(). I assume from your
comments below, that if you see a NSString that it's always just
plain text, a NSNumber is just a number, etc. If you do need to
support NSRects and such, then perhaps adding some type info would
not be such a bad idea as your code would then know exactly what to
do with each type/value pair.
steve
On Nov 12, 2007, at 2:50 PM, Gordon Apple wrote:
It's good to know this exists. I had never seen this.
However, it
still doesn't help in encoding an NSDictionary. You have to put these
things into an NSValue just to get them into the dictionary. Then
if you
want to encode the dictionary, you have to iterate through the
dictionary
and test every entry for every particular type of NSValue to encode
it.
Then, I'm still not sure how to decode it unless you encode Type
info with
it.
In my case, I have more than one NSDictionary, each of which
hasn't an a
priori clue as to what it contains. The keys and objects/values
are filled
in from elsewhere. Everything contained conforms to NSCoding.
What I would
like is to be able to just tell it to archive/unarchive the
dictionary and
be done with it.
How about NSGeometryKeyedCoding (see NSKeyedArchiver.h) :
@interface NSCoder (NSGeometryKeyedCoding)
- (void)encodePoint:(NSPoint)point forKey:(NSString *)key;
- (void)encodeSize:(NSSize)size forKey:(NSString *)key;
- (void)encodeRect:(NSRect)rect forKey:(NSString *)key;
- (NSPoint)decodePointForKey:(NSString *)key;
- (NSSize)decodeSizeForKey:(NSString *)key;
- (NSRect)decodeRectForKey:(NSString *)key;
@end
_______________________________________________
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