Skip to content

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

@ghost

Description

@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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions