Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Swizzling valueForKey: and objectForKey:
#import <objc/runtime.h>
@implementation NSDictionary (Swizzled)
static void swizzInstance(Class class, SEL originalSel, SEL newSel)
Method origMethod = class_getInstanceMethod(class, originalSel);
Method newMethod = class_getInstanceMethod(class, newSel);
method_exchangeImplementations(origMethod, newMethod);
- (id)zzz_valueForKey:(NSString *)key
return [self zzz_valueForKey:key];
- (id)zzz_objectForKey:(NSString *)key
return [self zzz_objectForKey:key];
+ (void)swizz

This comment has been minimized.

Copy link

@ooopscc ooopscc commented May 10, 2014

It seems that objectForKey: not working. I have tried for many times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment