jrswizzle
jrswizzle copied to clipboard
In origin method call super, the swizzling method will be called twice.
@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?
How to fix this bug ?