//
//  RangersAppLogSwizzle.m
//  react-native-rangers-applog-reactnative-plugin
//
//  Created by bytedance on 2022/6/27.
//

#import "RangersAppLogSwizzle.h"


IMP bd_swizzle_instance_methodWithBlock_rn(Class c, SEL origSEL, id block) {
    NSCParameterAssert(block);
    Method origMethod = class_getInstanceMethod(c, origSEL);
    NSCParameterAssert(origMethod);
    const char *types = method_getTypeEncoding(origMethod);
    IMP newIMP = imp_implementationWithBlock(block);
    IMP oldIMP = method_getImplementation(origMethod);

    BOOL didAddMethod = class_addMethod(c, origSEL, newIMP, types);
    if (!didAddMethod) {
        /// self has method
        class_replaceMethod(c, origSEL, newIMP, types);
    }

    return oldIMP;
}
