objective-cswiftreact-native

Strange issue 'Cannot find type 'RCTResponseSenderBlock' in scope' on Swift module React Native


I have a very strange problem: "Can't find the type RCTResponseSenderBlock in scope." It's strange, because in one case it is there and in the other it doesn't, looks like a bug.

This is screenshot issue.

This my Objective-C file:

#import <Foundation/Foundation.h>
#import "React/RCTBridgeModule.h"
#import <React/RCTEventEmitter.h>
#import <React/RCTConvert.h>

@interface RCT_EXTERN_MODULE(BLEclass, NSObject)

RCT_EXTERN_METHOD(addEvent:(NSString *)name callback:(RCTResponseSenderBlock)callback )

@end

And this my Swift file, where i have issue :

import Foundation

@objc(BLEclass)
class BLEclass: NSObject{
  @objc(addEvent:callback:)
    func addEvent(_ name: String,_ callback:RCTResponseSenderBlock){
      NSLog("%@", name);
      let resultsDict = [
           "name" : name
           ];
      callback([NSNull(),resultsDict])
     }
}

If you know how to fix it, please write answer.

Thanks.


Solution

  • I had this same issue and discovered I had to add the import to my main bridge file.

    #import <React/RCTBridgeModule.h>
    #import <React/RCTViewManager.h>
    

    I out which file was set by looking at the Build settings under Swift Compiler - General -> Objective-C Bridging Header which appears to be the default for the app.