Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "NSObject+DSKVO.h"
- #import <objc/runtime.h>
- @implementation NSObject (DSKVO)
- + (void)load
- {
- [self switchMethod];
- }
- // 交换后的方法
- - (void)removeDasen:(NSObject *)observer forKeyPath:(NSString *)keyPath
- {
- @try {
- [self removeDasen:observer forKeyPath:keyPath];
- } @catch (NSException *exception) {}
- }
- + (void)switchMethod
- {
- SEL removeSel = @selector(removeObserver:forKeyPath:);
- SEL myRemoveSel = @selector(removeDasen:forKeyPath:);
- Method systemRemoveMethod = class_getClassMethod([self class],removeSel);
- Method DasenRemoveMethod = class_getClassMethod([self class], myRemoveSel);
- method_exchangeImplementations(systemRemoveMethod, DasenRemoveMethod);
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement