• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to archive structs like NSRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: How to archive structs like NSRect (From: Gordon Apple <email@hidden>)

  • Prev by Date: CIFilter Problems Under Leopard
  • Next by Date: Re: How to archive structs like NSRect
  • Previous by thread: Re: How to archive structs like NSRect
  • Next by thread: Re: How to archive structs like NSRect
  • Index(es):
    • Date
    • Thread