class_copyMethodList

unsigned int count;

    // 获得方法数组

    //1.对象方法(减号方法)

    //2.(只在.h中声明,没在.m中实现,没有),(没在.h中声明,在.m中实现,有)

    //3.有属性的话,会多出.cxx_destruct方法

    Method*methodList =class_copyMethodList(cls, &count);

    // 存储方法名

    NSMutableString *methodNames = [NSMutableString string];

    // 遍历所有的方法

    for(int i =0; i < count; i++) {

        // 获得方法

        Method method = methodList[i];

        // 获得方法名

        NSString *methodName = NSStringFromSelector(method_getName(method));

        // 拼接方法名

        [methodNames appendString:methodName];

        [methodNames appendString:@", "];

    }

    // 释放

    free(methodList);

    // 打印方法名

    NSLog(@"%@ - %@", cls, methodNames);

你可能感兴趣的:(class_copyMethodList)