Swizzling UIButton example
+ (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; SEL originalSelector = @selector(_sendActionsForEvents: withEvent; SEL swizzledSelector = @selector(fb_sendActionsForEvents: withEvent; Method originalMethod = class_getInstanceMethod(class, originalSelector); Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (didAddMethod) { class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); } else { method_exchangeImplementations(originalMethod, swizzledMethod); } }); }- (void)fb_sendActionsForEvents:(UIControlEvents)controlEvents withEvent:(UIEvent *)event { if (controlEvents == UIControlEventTouchUpInside) { DKFireBaseEventsManager *manager = [[DKFireBaseEventsManager alloc] init]; [manager logButtonAction:self.titleLabel.text]; } [self fb_sendActionsForEvents:controlEvents withEvent:event];}
Комментарии
Отправить комментарий