Re: ivars and fundamental types
Re: ivars and fundamental types
- Subject: Re: ivars and fundamental types
- From: Greg Parker <email@hidden>
- Date: Mon, 11 Oct 2010 13:09:53 -0700
On Oct 8, 2010, at 9:18 PM, Dave Keck wrote:
>> object_setIvar() takes type id.
>
> object_getInstanceVariable()?
>
> "outValue: On return, contains a pointer to the value of the instance variable."
Don't do that. object_getInstanceVariable() and object_setInstanceVariable() still assume the ivar is of an object pointer type.
Instead, use class_getInstanceVariable() and ivar_getOffset() and pointer arithmetic.
Ivar ivar = class_getInstanceVariable([YourClass class], "YourIvarName");
assert(ivar);
int *ivarPtr = (int *)((uint8_t *)obj + ivar_getOffset(ivar));
*ivarPtr = 42;
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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