react-native: [iOS] Integrating into existing app: RCTJSCWrapper.h 'string' file not found

I’m attempting to integrate a React Native component into an existing Swift app. I am following the instructions here: https://facebook.github.io/react-native/docs/embedded-app-ios.html

  1. The documentation is unclear on the steps to bridge the RN view to the Swift app. It says to create a ReactView.h, and then a ViewController.m, and then goes on to say “For Swift apps there is no need for that.” No need for what - the ViewController.m, the ReactView.h, or both??? Very poor wording.
  2. Either way, when I create a ReactView.swift file:
import UIKit
import React

class ReactView: UIView {

  let rootView: RCTRootView = RCTRootView(bundleURL: NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios"),
    moduleName: "SimpleApp", initialProperties: nil, launchOptions: nil)

  override func layoutSubviews() {
    super.layoutSubviews()

    loadReact()
  }

  func loadReact () {
        addSubview(rootView)
        rootView.frame = self.bounds
  }
}

And import it into a View in Xcode, when I build the project I get the following error:

RCTJSCWrapper.h: 'string' file not found ReactView.swift: Could not build Objective-C module 'React'

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 11
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Alright, I’ve changed the API in https://github.com/facebook/react-native/commit/85983d0ae4fac0fc22048bd0d729cdc3ca755d91. Can you guys test it now?

I think more fundamentally this is because RCTJSCWrapper.h has a C++ dependency in the header itself (a typedef using std::string), effectively in React’s public API, which means the React module exposed by the Pod isn’t a valid Objective-C module and one result is that it can’t be imported by swift.

It looks like it ought to be straightforward to change this signature to a const char * and restore Objective-C compatibility (eg https://github.com/rh389/react-native/commit/013285bcace15ea8894a8f0fd0f22252e3b513b8), but I don’t well enough understand what this JSCWrapper is actually doing or what it’s for.

Looks like one for @alexeylang ?