Re: Encoding an integer in another object
Re: Encoding an integer in another object
- Subject: Re: Encoding an integer in another object
- From: "Clark S. Cox III" <email@hidden>
- Date: Wed, 04 Sep 2002 11:50:15 -0400
On 09/04/2002 11:32, "Bertil Holmberg" <email@hidden>
wrote:
>
I would like my Document to encode an int from my WindowController.
>
Since the second parameter to encodeValueOfObjCType:at: is an address, I
>
can not use an ordinary access routine that returns the value, not the
>
address. So I tried this kludge that seem to work:
>
>
In the Document:
>
[coder encodeValueOfObjCType:@encode(unsigned int) at:[wController
>
addressOfMyInt]];
>
>
In the WindowController:
>
- (void *)addressOfMyInt {
>
return &myInt;
>
}
>
>
Is there a more elegant solution to this?
Yes, in the WindowController:
- (unsigned)myInt {
return myInt;
}
In the Document:
unsigned tempInt = [wController myInt];
[coder encodeValueOfObjCType:@encode(unsigned int) at:&tempInt]
>
>
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;
>
>
I would be very grateful if anyone could explain to me why the
>
parameters are declared differently. In Learning Cocoa they are used in
>
the same way which makes sense to me if I assume that they are both addresses.
The const simply means that the encodeValueOfObjCType:at: method won't
change the value pointed to by addr.
--
http://homepage.mac.com/clarkcox3/
Clark S. Cox III
_______________________________________________
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.