您的位置:首页 > 移动开发 > IOS开发

iOS 获取一个类的所有方法

2013-07-27 09:47 267 查看
#import <objc/runtime.h>
#import <objc/message.h>

需要导入运行时头文件和消息发送文件
- (void)runTests
{
    unsigned int count;
    Method *methods = class_copyMethodList([self
class], &count);
    for (int i =
0; i < count; i++)
    {
        Method method = methods[i];
        SEL selector = method_getName(method);
        NSString *name = NSStringFromSelector(selector);
//        if ([name hasPrefix:@"test"])
        NSLog(@"方法
名字 ==== %@",name);
        if (name)
        {
            //avoid arc warning by using c runtime
//            objc_msgSend(self, selector);
        }
        
        NSLog(@"Test '%@' completed successfuly", [name
substringFromIndex:4]);
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: