Skip to content

Instantly share code, notes, and snippets.

@nicolastinkl
Created December 14, 2016 04:03
Show Gist options
  • Save nicolastinkl/8b1aa7ffea9e0657fb660d1a19dd38a9 to your computer and use it in GitHub Desktop.
Save nicolastinkl/8b1aa7ffea9e0657fb660d1a19dd38a9 to your computer and use it in GitHub Desktop.
NSMutNSableDictionary (Safe)
@implementation NSMutNSableDictionary(Swizzing)
+ (void)load {
Class dictCls = NSClassFromString(@"__NSDictionaryM");
Method originalMethod = class_getInstanceMethod(dictCls, @selector(setObject:forKey:));
Method swizzledMethod = class_getInstanceMethod(dictCls, @selector(na_setObject:forKey:));
method_exchangeImplementations(originalMethod, swizzledMethod);
}
- (void)na_setObject:(id)anObject forKey:(id<NSCopying>)aKey {
NSLog(@"anObject : %@ ",anObject);
if (!anObject)
return;
[self na_setObject:anObject forKey:aKey];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment