TYSwizzleDemo method swizzling easy to use,C Function and NSObject Categary
我已经把 method swizzling 封装成 C 函数 和 NSObject 分类 ,使用非常简单,demo附带测试
C Function
// exchange instance method
BOOL ty_swizzleInstanceMethod(Class aClass, SEL originalSel, SEL replacementSel);
// exchange class method
BOOL ty_swizzleClassMethod(Class aClass, SEL originalSel, SEL replacementSel);
// exchange method with IMP, and store orignal IMP
BOOL ty_swizzleMethodAndStoreIMP(Class aClass, SEL originalSel, IMP replacementIMP,IMP *orignalStoreIMP);
IMP ty_swizzleMethodIMP(Class aClass, SEL originalSel, IMP replacementIMP);
测试环境:Xcode 6.2,iOS 6.0 以上
NSObject Categary
// exchange instance method
+ (BOOL)ty_swizzleMethodWithOrignalSel:(SEL)orignalSel replacementSel:(SEL)replacementSel;
// exchange class method
+ (BOOL)ty_swizzleClassMethodWithOrignalSel:(SEL)orignalSel replacementSel:(SEL)replacementSel;
// exchange method with IMP, and store orignal IMP
+ (BOOL)ty_swizzleMethodWithOrignalSel:(SEL)orignalSel replacementIMP:(IMP)replacementIMP orignalStoreIMP:(IMP *)orignalStoreIMP;
+ (IMP) ty_swizzleMethodWithOrignalSel:(SEL)orignalSel replacementIMP:(IMP)replacementIMP;