如何獲取特定類的類方法的列表?我試過使用<objc/runtime.h>
中聲明的class_copyMethodList
函數,但這只是給我實例方法。我也發現了一個函數,它給了我一個類方法的方法,但只有當我有選擇器的方法(class_getClassMethod
)。獲取任意類的類方法列表
任何想法?
感謝,
戴夫
如何獲取特定類的類方法的列表?我試過使用<objc/runtime.h>
中聲明的class_copyMethodList
函數,但這只是給我實例方法。我也發現了一個函數,它給了我一個類方法的方法,但只有當我有選擇器的方法(class_getClassMethod
)。獲取任意類的類方法列表
任何想法?
感謝,
戴夫
class_copyMethodList
返回傳入類的實例方法。類方法實際上是類的元類的實例方法。
對於class_copyMethodList
,您的問題的解決方案包含在API Documentation中。
使用元類。
#import <objc/runtime.h>
int unsigned numMethods;
Method *methods = class_copyMethodList(objc_getMetaClass("NSArray"), &numMethods);
for (int i = 0; i < numMethods; i++) {
NSLog(@"%@", NSStringFromSelector(method_getName(methods[i])));
}
free(methods);
完美,謝謝!我不能相信我錯過了這一點。 = P – 2009-08-15 20:40:05