• 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: Specifying primitive types in NSCoders
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Specifying primitive types in NSCoders
      • From: Marcel Weiher <email@hidden>
References: 
 >Specifying primitive types in NSCoders (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Getting key events when the program is in the background?
  • Next by Date: Re: Specifying primitive types in NSCoders
  • Previous by thread: Specifying primitive types in NSCoders
  • Next by thread: Re: Specifying primitive types in NSCoders
  • Index(es):
    • Date
    • Thread