replace this. D Another third-party library replacement same method at the same time on another thread @implementation GeneralSwz + (void)load { Method originalMethod = class_getInstanceMethod(self, @selector(foo)); Method swizzledMethod = class_getInstanceMethod(self, @selector(swz_foo)); method_exchangeImplementations(originalMethod, swizzledMethod); } @end
{ NSLog(@"original foo method"); } @end @interface General : Bare @end @implementation General @end Base Class - (void)foo General Class Inherited Class - (void)foo Swizzle `foo` method
Written by Mattt Thompson on February 17th, 2014 D http://nshipster.com/method-swizzling/ D The Right Way to Swizzle in Objective-C D http://blog.newrelic.com/2014/04/16/right-way-to-swizzle/ D What are the Dangers of Method Swizzling in Objective C? D http://stackoverflow.com/questions/5339276/what-are-the-dangers-of-method-swizzling-in- objective-c/8636521#8636521 D rabovik/RSSwizzle D https://github.com/rabovik/RSSwizzle D http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/libkern/libkern/OSAtomic.h D Objective-C Runtime Reference D https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/ index.html#//apple_ref/c/func/method_getImplementation