Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- + (void)load {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- SEL systemSEL = @selector(sendAction:to:forEvent:);
- SEL replaceSEL = @selector(SG_sendAction:to:forEvent:);
- Method systemMethod = class_getInstanceMethod(self, systemSEL);
- Method replaceMethod = class_getInstanceMethod(self, replaceSEL);
- BOOL isAdd = class_addMethod(self, systemSEL, method_getImplementation(replaceMethod), method_getTypeEncoding(replaceMethod));
- if (isAdd) {
- class_replaceMethod(self, replaceSEL, method_getImplementation(systemMethod), method_getTypeEncoding(systemMethod));
- } else {
- // 添加失败,说明本类中有 replaceMethod 的实现,此时只需要将 systemMethod 和 replaceMethod 的IMP互换一下即可
- method_exchangeImplementations(systemMethod, replaceMethod);
- }
- });
- }
Add Comment
Please, Sign In to add comment