RunTime API

一、 获取方法列表----class_copyMethodList
method_getName、sel_getName

NSArray* MethodsOfClass(Class cls){
    NSMutableArray *methodObjs = @[].mutableCopy;
    unsigned int methodCount = 0;
    Method *methods = class_copyMethodList(cls, &methodCount);
    if (methods) {
        for (unsigned int i =0; i 

二、 获取属性列表 class_copyIvarList

ivar_getName、ivar_getTypeEncoding

  - (void)iVarGetClassNameList:(Class)cls{
    unsigned int outCount; // 1
    Ivar *ivars = class_copyIvarList(cls, &outCount); // 2

    for (int i = 0; i < outCount; i++) { // 3
        Ivar ivar = ivars[i]; // 4
        const char *ivarName = ivar_getName(ivar); // 5
        const char *ivarType = ivar_getTypeEncoding(ivar); // 6
        NSLog(@"实例变量名为:%s 字符串类型为:%s", ivarName,ivarType); // 7
    } // 8
    free(ivars);
}

你可能感兴趣的:(RunTime API)