You just need to get a list of methods and find the one you need:
#import <objc/runtime.h> BOOL hasMethod(Class cls, SEL sel) { unsigned int methodCount; Method *methods = class_copyMethodList(cls, &methodCount); BOOL result = NO; for (unsigned int i = 0; i < methodCount; ++i) { if (method_getName(methods[i]) == sel) { result = YES; break; } } free(methods); return result; }
class_copyMethodList returns only methods that are defined directly in the class in question, and not in superclasses, so this should be what you mean.
If you need class methods, use class_copyMethodList(object_getClass(cls), &count) .
Rob napier
source share