MYNSUserDefaults - (id)valueForKeySwizzled:(NSString *)key { return @"SetByMethodSwizzling"; } @end @implementation MethodSwizzlingTests - (void)testUserDefaultsSwitch { Method original = class_getInstanceMethod( [NSUserDefaults class], @selector(valueForKey:)); Method swizzled = class_getInstanceMethod( [MYNSUserDefaults class], @selector(valueForKeySwizzled:)); method_exchangeImplementations(original, swizzled); NSString * key = [[NSUserDefaults standardUserDefaults] valueForKey:@"aKey"]; STAssertEquals(key, @"SetByMethodSwizzling", @"should be nil"); } @end