欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS----------Runtime 获取属性列表 方法列表

程序员文章站 2022-09-07 13:02:25
导入 #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);