Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesNotRecognizeSelector after removing hooks of subclass #155

Open
JerryChu opened this issue Dec 28, 2018 · 0 comments
Open

doesNotRecognizeSelector after removing hooks of subclass #155

JerryChu opened this issue Dec 28, 2018 · 0 comments

Comments

@JerryChu
Copy link

JerryChu commented Dec 28, 2018

sample project: Aspect_issue.zip

  1. add a hook for superclass, e.g. UIViewController
    [UIViewController aspect_hookSelector:@selector(viewDidAppear:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info) {
        NSLog(@"hooked viewDidAppear!");
    } error:NULL];
  1. add a hook for subclass, e.g. ViewController
    id<AspectToken> token = [ViewController aspect_hookSelector:@selector(foo) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info) {
        NSLog(@"hooked foo!");
    } error:NULL];
  1. remove the hook of subclass
    [token remove];

Then, when ViewController's [super viewDidAppear:] is called, it will trigger a doesNotRecognizeSelector crash.

It is because that when the hook token is removed from ViewController, Aspect finds ViewController has no hooks, so aspect_undoSwizzleForwardInvocation is called, resetting ViewController's forwardInvocation to the original method (which is nil, and Aspect uses NSObject's forwardInvocation implementation instead ).

JerryChu referenced this issue in JerryChu/Aspects Dec 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant