steipete / Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.
https://twitter.com/steipete
MIT License
8.4k stars 1.26k forks source link

Written methods and function blocks not called #39

Open Morkrom opened 9 years ago

Morkrom commented 9 years ago

"aspect_hook" blocks are not being called for me for methods (or dynamic swift functions). If I use a comparable implementation such as this, it works for public methods as expected.

It seems the issue lies partly in the aspect_isCompatibleBlockSignature function... if the method being intercepted is a dynamic swift function, there is a mismatch around line 210 in .m:

if (signaturesMatch) { For loop, the condition for signaturesMatch = NO is not compatible with a dynamic Swift function. }

commenting out this loop allows a dynamic Swift function to work correctly.

If it is an objective-C method, the mismatch occurs due to the blockSignature's numberOfArguments being larger than the methodSignature.

I am still trying to figure out what all this means, and if I do I will attempt a solution. Otherwise some help would be great because I really want to use it.

igiu1988 commented 6 years ago

I have the same question. I aspect tableView:didSelectRowAtIndexPath:

[self aspect_hookSelector:@selector(tableView:didSelectRowAtIndexPath:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info, UITableView *tableView, NSIndexPath *indexPath) {.....

when code run into invokeWithInfo, it happens "blockSignature's numberOfArguments being larger than the methodSignature."