• 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: Encoding an integer in another object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Encoding an integer in another object


  • Subject: Re: Encoding an integer in another object
  • From: Ondra Cada <email@hidden>
  • Date: Wed, 4 Sep 2002 19:17:48 +0200

On Wednesday, September 4, 2002, at 05:32 , Bertil Holmberg wrote:

According to the declaration of encodeValueOfObjCType:at: the second
param should be (const void*)addr, but if I use this type in my
accessor, the compiler protests on the decoding version which has (void *)data.

- (void)encodeValueOfObjCType:(const char *)type at:(const void *)addr;
- (void)decodeValueOfObjCType:(const char *)type at:(void *)data;

Oh, my -- this is no more programming, this is just common sense:

(i) when you are encoding, the data are just read from the variable: therefore, it quite naturally is accessed as a const (to emphasize and ensure that the method could not change the data);
(ii) when you are decoding, the data by definition are changed; therefore,
it can't be a const.

Agreeably for int and similar another kind of encode/decode methods would be better (encode just etting an int value, decode just returning an int value); it is so in Jaguar, luckily. The way it is no you have to use a superfluous variable:

int foo=[self myFooGetter];
[coder encodeValueOfObjCType:@encode(int) at:&foo];

int foo;
[coder decodeValueOfObjCType:@encode(int) at:&foo];
[self myFooSetter:foo];

The API was created with an idea that you won't use getter/setter in archiving/unarchiving, but that you would access ivars there directly. It proved to be generally a bad idea, but well, this API is quite old ;) If you can afford it, go 10.2, and use the new API.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.
References: 
 >Encoding an integer in another object (From: Bertil Holmberg <email@hidden>)

  • Prev by Date: Re: if statements vs. switch
  • Next by Date: NSDrawer and preferredEdge
  • Previous by thread: Re: Encoding an integer in another object
  • Next by thread: dropping a subclassed TextAttachmentCell from within a NSTextView
  • Index(es):
    • Date
    • Thread