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 loop through the methods of class_copyMethodList()
, but since I might want to check a lot of instances, I wanted to know if there was a simpler solution (like repondsToSelector:
, but restricted to the class itself...)
edit: since I really think there is no function or method doing that, I wrote mine. Thanks for your answers, here is the method if it can be of any use :
+ (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;
}