Support for Multiple Hooks into Methods in Class Hierarchy
Currently the first hook to a class wins, so if B subclasses A, and both implement foo, we can either hook foo in A or in B, but not in both classes.
This is related to #2. The basic problem is that once we have an NSInvocation, there's no way to check the underlying IMP location to detect if it points to self or super... so hooks can only safely be added to the topmost class.
Currently I opted to block this, but it's by far not the best solution. We can also collect and apply this in alloc-time. Downside: Hooks might be called whose method is not (you might wanna omit super, but the hook for the parent would still be called - also the timing would be different)
Alternatively we could fix the underlying problem, but it requires custom jump tables ala https://github.com/OliverLetterer/SPLMessageLogger/blob/master/SPLMessageLogger/spl_forwarding_trampoline_armv7.s#L14-L18 (or maybe libffi)
@steipete It seems that this applies not only to subclasses, but to any class with common base classes? Is that right?
For example, if I have two classes derived from NSObject, and each implements a function called "someFunction", this situation also applies. Or, in a more realistic case, if I have two UIViewControllers, each which implements the same protocol, I can't seem hook that protocol method in both places.
I think i fixed this and relative issues, but i don't know how to submit, send email to me ([email protected])
@pj4533 I just met the same issue as you mentioned.I was trying to hook a table view delegate method in different classes, but the error log says:
"tableView:didSelectRowAtIndexPath: already hooked in
YIDSignUpViewController. A method can only be hooked once per class hierarchy."
The strange thing is, in fact, I didn't hook any table view delegate methods in YIDSignUpViewController class and I didn't implement any table view delegate methods in that class .