diff --git a/packages/react-native/ReactCommon/react/test_utils/ios/RCTSwizzleHelpers.h b/packages/react-native/ReactCommon/react/test_utils/ios/RCTSwizzleHelpers.h new file mode 100644 index 00000000000..79ca15d2a65 --- /dev/null +++ b/packages/react-native/ReactCommon/react/test_utils/ios/RCTSwizzleHelpers.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#import + +RCT_EXTERN_C_BEGIN + +void RCTSwizzleInstanceSelector( + Class targetClass, + Class swizzleClass, + SEL selector); + +RCT_EXTERN_C_END diff --git a/packages/react-native/ReactCommon/react/test_utils/ios/RCTSwizzleHelpers.m b/packages/react-native/ReactCommon/react/test_utils/ios/RCTSwizzleHelpers.m new file mode 100644 index 00000000000..989a3474b73 --- /dev/null +++ b/packages/react-native/ReactCommon/react/test_utils/ios/RCTSwizzleHelpers.m @@ -0,0 +1,17 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTSwizzleHelpers.h" + +#import + +void RCTSwizzleInstanceSelector(Class targetClass, Class swizzleClass, SEL selector) +{ + Method originalMethod = class_getInstanceMethod(targetClass, selector); + Method swizzleMethod = class_getInstanceMethod(swizzleClass, selector); + method_exchangeImplementations(originalMethod, swizzleMethod); +}