Is it possible to check whether a subclass implements a method that exists either in its immediate superclass or in some superclass of its superclass, etc?
E.g. I subcla
Based on this answer by Mert Buran.
You can create a simple method to check whether a given object overrides a given selector (method):
-(BOOL)checkIfObject:(id)object overridesSelector:(SEL)selector {
Class objSuperClass = [object superclass];
BOOL isMethodOverridden = NO;
while (objSuperClass != Nil) {
isMethodOverridden = [object methodForSelector: selector] !=
[objSuperClass instanceMethodForSelector: selector];
if (isMethodOverridden) {
break;
}
objSuperClass = [objSuperClass superclass];
}
return isMethodOverridden;
}
This can be called as follows:
[self checkIfObject:someObject overridesSelector:@selector(someSelector)];