• 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: ivars and fundamental types
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: ivars and fundamental types
      • From: Dave Keck <email@hidden>
References: 
 >ivars and fundamental types (From: Rick Mann <email@hidden>)
 >Re: ivars and fundamental types (From: Sherm Pendley <email@hidden>)
 >Re: ivars and fundamental types (From: Rick Mann <email@hidden>)
 >Re: ivars and fundamental types (From: Dave Keck <email@hidden>)

  • Prev by Date: Re: Identifying Cocoa Methods
  • Next by Date: Re: Return key should enter return in textfield and not press default button
  • Previous by thread: Re: ivars and fundamental types
  • Next by thread: Re: ivars and fundamental types
  • Index(es):
    • Date
    • Thread