我有一个对象,我想列出它响应的所有选择器。感觉这应该是完全可能的,但我找不到 API。
最佳答案
这是一个基于运行时 C 函数的解决方案:
class_copyMethodList 返回一个类方法列表,给定一个可从对象获得的 Class 对象。
#import <objc/runtime.h>
[..]
SomeClass * t = [[SomeClass alloc] init];
int i=0;
unsigned int mc = 0;
Method * mlist = class_copyMethodList(object_getClass(t), &mc);
NSLog(@"%d methods", mc);
for(i=0;i<mc;i++)
NSLog(@"Method no #%d: %s", i, sel_getName(method_getName(mlist[i])));
/* note mlist needs to be freed */
关于objective-c - Objective-C 对象的列表选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/330030/