获取类的成员变量(ios)
unsigned
int
numIvars;
Ivar
*vars =
class_copyIvarList(NSClassFromString(@"TestView"),
&numIvars);
NSString
*key=nil;
for(int
i =
0; i < numIvars; i++) {
Ivar thisIvar = vars[i];
key = [NSString
stringWithUTF8String:ivar_getName(thisIvar)];
//获取成员变量的名字
NSLog(@"variable name :%@", key);
key = [NSString
stringWithUTF8String:ivar_getTypeEncoding(thisIvar)];
//获取成员变量的数据类型
NSLog(@"variable type :%@", key);
}
free(vars);
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-08 22:16:56