#import
@interfaceNSMutableDictionary (objc)
@end
#import "NSMutableDictionary+objc.h"
#import
@implementationNSMutableDictionary (objc)
+ (void)load {
//这个是类簇,实际的字典,这个必须得用这个形式,使用self不行
Class dictCls = NSClassFromString(@"__NSDictionaryM");
MethodoriginalMethod =class_getInstanceMethod(dictCls,@selector(setObject:forKey:));
MethodswizzledMethod =class_getInstanceMethod(dictCls,@selector(na_setObject:forKey:));
method_exchangeImplementations(originalMethod, swizzledMethod);
}
- (void)na_setObject:(id)anObject forKey:(id)aKey {
if(!anObject)
return;
[selfna_setObject:anObjectforKey:aKey];
}
@end