1

I am developing a new feature for a react native module (https://github.com/blackuy/react-native-twilio-video-webrtc) the thing is it is developed in Objective-C and I need to import a new Swift class.

What I've done so far:

  1. Importing it with the name of the package, in this case #import <RNTwilioVideoWebRTC/RNTwilioVideoWebRTC-Swift.h>
  2. Ensuring that Precompile Bridging Header is set to Yes
  3. Setting Objective-C Generated Interface Header Name as RNTwilioVideoWebRTC-Swift.h

The problem is then i try to run the example app inside the module, it prompts an error RNTwilioVideoWebRTC/RNTwilioVideoWebRTC-Swift.h file not found

What am I missing? Thanks!

Eduardo Palacio
  • 301
  • 1
  • 10

2 Answers2

0

There are a few things to make sure that:

  1. Check whether the bridging file is available in your project or not. If available, make sure that you have imported YourProductName-Swift.h in your bridge file. And if not, please create a bridge file.
  2. Mark the class & methods with @objc to make them accessible in your Objective C code.

You can follow this answer for reference.

Rahul
  • 474
  • 5
  • 8
0

Archiving will be successful already tested

How to call a swift function (that could be in a swift framework also) in objective c project or react native project

it will work for react-native also follow these steps :

Open Build Settings and check these parameters: Defines Module : YES

in AppDelegate.h

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>

@class KB;

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>

@property (strong, nonatomic) KB *appkb;

@end

in AppDelegate.m

#import "AppDelegate.h"
#import "ProductModuleName-Swift.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [self.appkb methodReceiveSwiftClass];
  [self.appkb methodEvents:event prop:properties];
}

@end

KB.swift

import Foundation
// import framework if using a swift framework in objective c or react native native modules.
@objc public class KB:NSObject{
  
  @objc public func methodReceiveSwiftClass(){
    //write anything here....
  }

  @objc public func methodEvents(_ event: String, prop: String){
    //write anything here
     //func with params
  }

}

ProjectModuleName-Bridging-Header.h

#import "React/RCTBridgeModule.h"
#import "AppDelegate.h"
Govind Wadhwa
  • 904
  • 8
  • 16