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

In origin method call super, the swizzling method will be called twice. #19

Open
ghost opened this issue Dec 10, 2016 · 1 comment
Open

Comments

@ghost
Copy link

ghost commented Dec 10, 2016

@implementation UIViewController (Swizzling)
+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        SEL originSelector = @selector(viewWillAppear:);
        SEL swizzleSelector = @selector(sw_viewWillAppear:);
        [self jr_swizzleMethod:originSelector withMethod:swizzleSelector error:nil];
    });
}

- (void)sw_viewWillAppear:(BOOL)animated {
    [self sw_viewWillAppear:animated];
    NSLog(@"I'm swizzling method");
}
@end
@implementation ViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"I'm origin method");
}
@end

When calling [super viewWillAppear:animated], the log--I'm swizzling method print twice. if not, print once.
So, whether or not to need call super?

@CrazyRedcrownedcrane
Copy link

How to fix this bug ?

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