Re: Dynamically getting the type of ivars
Re: Dynamically getting the type of ivars
- Subject: Re: Dynamically getting the type of ivars
- From: Greg Guerin <email@hidden>
- Date: Mon, 13 Apr 2009 13:25:16 -0700
Dave DeLong wrote:
unsigned int numIvars = 0;
Ivar * ivars = class_copyIvarList(aClass, &numIvars);
for (int i = 0; i < numIvars; i++) {
Ivar thisIvar = ivars[i];
Class ivarClass = somethingToGetTheIvarClassIfItsAnObject(thisIvar);
}
I can check to see if an Ivar is an object by checking to see if
the first character of ivar_getTypeEncoding(thisIvar) is the '@'
symbol (this, I believe, is documented to be true). However, since
all I have is an Ivar pointer, I'm not sure how I can get the
static type of the Ivar (if it's an object).
Call ivar_getTypeEncoding(Ivar) to get its type-encoding string. To
decipher the type-encoding string, see this:
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/
ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html
In particular, note:
"Objects are treated like structures."
-- GG
_______________________________________________
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