iOS----------Runtime 获取属性列表 方法列表
程序员文章站
2022-04-20 18:10:14
导入 #import unsigned int count; Method *methods = class_copyMethodList([UIAlertAction class], &count); for (int i = 0; i < count; i++) ......
导入
#import <objc/runtime.h>
unsigned int count;
method *methods = class_copymethodlist([uialertaction class], &count);
for (int i = 0; i < count; i++) {
method method = methods[i];
sel selector = method_getname(method);
nsstring *name = nsstringfromselector(selector);
nslog(@"method_getname:%@",name);
}
unsigned int numivars;
ivar *vars = class_copyivarlist([uialertaction class], &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);
}
free(vars);