Obtain list of class methods for an arbitrary class
-
16-09-2019 - |
Question
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
Solution
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
.
OTHER TIPS
Use the metaclass.
#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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow