This is pretty simple to check:
if (method_getImplementation(class_getInstanceMethod(A, @selector(methodRed))) == method_getImplementation(class_getInstanceMethod(B, @selector(methodRed)))) { // B does not override } else { // B overrides }
I need to wonder if it is useful to know that B overrides the method on A, but if you want to know this, here's how you find out.
It may also be worth noting: in the strict sense, the code above determines whether the implementation of the selector differs from B from the implementation of the selector by A. If you had a hierarchy A> X> B and X overriding the selector, it will still report different implementations between A and B, although B is not an override class. If you want to know for sure that "B cancels this selector (regardless of anything else)", you would like to do:
if (method_getImplementation(class_getInstanceMethod(B, @selector(methodRed))) == method_getImplementation(class_getInstanceMethod(class_getSuperclass(B), @selector(methodRed)))) { // B does not override } else { // B overrides }
This, perhaps, obviously asks the question: โB has a different implementation for the selector than its superclass,โ which (perhaps more specifically) is what you asked for.
ipmcc source share