Re: Specifying primitive types in NSCoders
Re: Specifying primitive types in NSCoders
- Subject: Re: Specifying primitive types in NSCoders
- From: Andy Lee <email@hidden>
- Date: Sat, 29 Jun 2002 12:22:10 -0400
At 11:50 AM -0400 6/29/02, Ken Tozier wrote:
I'm sure this is a simple one, but I can't find any concrete examples of
how to specify primitive types in encoding and decoding methods.
For example:
- (void)decodeValueOfObjCType:(const char *)valueType at:(void *)data
What exactly do you pass into "valueType"?
There is a clue in the doc for -decodeValuesOfObjCTypes:, which
directs us to look up the @encode() compiler directive. I admit this
hint is a little tricky to find.
A tactic that helps me is to use MTLibrarian to index the Examples
directory. If there's a class or method whose usage is unclear to
me, it helps to see how somebody else uses it. A search on
"decodeValueOfObjCType" turned up a file called ProgressCell.m, which
contains these lines:
[decoder decodeValueOfObjCType:@encode(float) at:&percentageIncrement];
[decoder decodeValueOfObjCType:@encode(float) at:&percentage];
[decoder decodeValueOfObjCType:@encode(int) at:&tag];
I also have the Objective-C documentation indexed in MTLibrarian, so
once I know there's a thing called @encode, I can quickly find docs
that explain it.
BTW, @encode works not only with primitive types, but with structs.
For example, you can say @encode(NSRect), which I did for a long time
until I noticed the -decodeRect method in NSCoder.
--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.