利用runtime 打印一个类中的所有方法名
/**
MJ: 利用runtime 打印方法名 #import <objc/runtime.h>
@param clsObj 类对象或者元类对象 [Method class]/obj_getClass([Method class])
*/
- (void)printMethodListsOfClass:(Class) clsObj {
// 1.获得方法数组
unsigned int count;
Method *methdList = class_copyMethodList(clsObj, &count);
// 2.存储方法名
NSMutableString *methodNames = [NSMutableString string];
// 3.遍历所有的方法
for (int i = 0; i < count; i++) {
// 3.1 获得方法
Method methodSelector= methdList[count];
// 3.2 获得方法名
NSString *methodName = NSStringFromSelector(method_getName(methodSelector));
// 3.3 拼接方法名--存储
[methodNames appendString:methodName];
[methodNames appendString:@","];
}
// 4.释放
free(methdList);
// 5.打印方法名
NSLog(@"%@----%@",clsObj, methodNames);
}
![](https://img.haomeiwen.com/i3415743/4642a7fd242da60c.png)
runtime打印方法名.png
本文标题:利用runtime 打印一个类中的所有方法名
本文链接:https://www.haomeiwen.com/subject/eaogoftx.html
网友评论