I would like to know if an instance implements a specific method. I could use respondsToSelector: but it returns YES if the instance inherits the method ...
I could have skipped class_copyMethodList() methods, but since I could have tested many instances, I wanted to know if there was a simpler solution (e.g. repondsToSelector: but limited to the class itself) ..)
edit: since I really think that there is no function or method, I wrote this. Thanks for your answers, here is this method, if it can be useful:
+ (BOOL)class:(Class)aClass implementsSelector:(SEL)aSelector { Method *methods; unsigned int count; unsigned int i; methods = class_copyMethodList(aClass, &count); BOOL implementsSelector = NO; for (i = 0; i < count; i++) { if (sel_isEqual(method_getName(methods[i]), aSelector)) { implementsSelector = YES; break; } } free(methods); return implementsSelector; }
source share