美文网首页Runtime
runtime-获取类的所有方法

runtime-获取类的所有方法

作者: Jerky_Guo | 来源:发表于2017-11-24 11:16 被阅读230次

首先导入头文件#import <objc/runtime.h>

#pragma mark - 获取类的所有方法
- (NSArray *)getClassMethods {
    
    NSMutableArray *mutArr = [NSMutableArray array];
    
    unsigned int outCount;
    
    /** 第一个参数:要获取哪个类的方法
     * 第二个参数:获取到该类的方法的数量
     */
    Method *methodList = class_copyMethodList([UIView class], &outCount);
    
    // 遍历所有属性列表
    for (int i = 0; i<outCount; i++) {
        SEL name = method_getName(methodList[i]);
        [mutArr addObject:NSStringFromSelector(name)];
    }
    return [NSArray arrayWithArray:mutArr];
}

相关文章

网友评论

    本文标题:runtime-获取类的所有方法

    本文链接:https://www.haomeiwen.com/subject/xzmxbxtx.html