views:

341

answers:

2

How can I get the list of class methods for a particular Class? I've tried using the class_copyMethodList function declared in <objc/runtime.h>, but that's only giving me instance methods. I've also found a function that gives me a Method for a class method, but only if I have the selector to the method first (class_getClassMethod).

Any ideas?

Thanks,

Dave

+7  A: 

class_copyMethodList returns the instance methods of the passed class. The class methods are actually instance methods of the class's metaclass.

The solution to your problem is included right in the API Documentation for class_copyMethodList.

Jim Correia
Perfect, thanks! I can't believe I missed that. =P
Dave DeLong
+3  A: 

Use the metaclass.

int unsigned numMethods;
Method *methods = class_copyMethodList(objc_getMetaClass("NSArray"), &numMethods);
for (int i = 0; i < numMethods; i++) {
    NSLog(@"%@", NSStringFromSelector(method_getName(methods[i])));
}