Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #import "NSObject+DSKVO.h"
  2. #import <objc/runtime.h>
  3. @implementation NSObject (DSKVO)
  4.  
  5. + (void)load
  6. {
  7. [self switchMethod];
  8. }
  9.  
  10. // 交换后的方法
  11. - (void)removeDasen:(NSObject *)observer forKeyPath:(NSString *)keyPath
  12. {
  13. @try {
  14. [self removeDasen:observer forKeyPath:keyPath];
  15. } @catch (NSException *exception) {}
  16. }
  17.  
  18. + (void)switchMethod
  19. {
  20. SEL removeSel = @selector(removeObserver:forKeyPath:);
  21. SEL myRemoveSel = @selector(removeDasen:forKeyPath:);
  22.  
  23. Method systemRemoveMethod = class_getClassMethod([self class],removeSel);
  24. Method DasenRemoveMethod = class_getClassMethod([self class], myRemoveSel);
  25.  
  26. method_exchangeImplementations(systemRemoveMethod, DasenRemoveMethod);
  27. }
  28.  
  29. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement