Lot of question are asked regarding the same but none of them solve my error.
Here is my objective c file
#import <Foundation/Foundation.h>#import <React/RCTBridgeModule.h>#import <UIKit/UIKit.h>@interface RCT_EXTERN_MODULE(LanguageTranslationModule, NSObject)RCT_EXTERN_METHOD(callbackMethod:(NSString*)englishText (RCTResponseSenderBlock)callback)@end
Here is my swift class
@objc(LanguageTranslationModule)class LanguageTranslationModule: NSObject { var resultCallback: RCTResponseSenderBlock! @objc func callbackMethod(_ englishText: String, callback: @escaping RCTResponseSenderBlock) -> Void { resultCallback = callback debugPrint("Hi there") translateText(msg: englishText) }...
Here is my JS call from React Native
LanguageTranslationModule.callbackMethod(englishText, (err, r) => { if (!err) { setProgress(false); setMarathiText(r.text.toString()); } else { setProgress(false); setMarathiText(err); } });
have added underscore to my first parameter in swift file as that is most of the solution to other questions asked on stack as well as there is space between the underscore and actual variable name. If I remove the englishText variable from all the files and hardcode that text in swift file then my function works fine. of course then I had to add underscore to the callback variable, so no logical error from my side