39

I have a react native component written in Swift, and I want to extract it as a framework so other project/people can use it easily.

First I created a new iOS project Foo, added a framework target, then added source files. Finally, I built it.

It failed because:

Bar.swift:[lineNumber]: Use of unresolved identifier 'RCTConvert' RNBarManager.swift:[lineNUmber]: Use of undeclared type 'RCTViewManager'

Attempt 1:

I ran react-native link, but nothing changed.

Attempt 2:

  1. Drag React.xcodeproj to Foo project and add libReact.a to Link Binary With Libraries.
  2. Add $(SRCROOT)/../node_modules/react-native/React to Header Search Paths.

But it doesn't work. The error still remains.

Attempt 3:

I was thinking maybe Swift doesn't recognize these files.

So I added Foo-Bridging-Headers.h like I did in a React-Native App, which contains the following code:

#import "React/RCTBridge.h"
#import "React/RCTViewManager.h"
#import "React/RCTUIManager.h"
#import "React/UIView+React.h"
#import "React/RCTBridgeModule.h"

I also added Foo-Bridging-Headers.h to Build Settings->Swift Compiler - General->Object-C Bridging Header,

Still I got an error.

using bridging headers with framework targets is unsupported

It seems bridging headers are not allowed here.

Attempt 4:

I tried to add these imports to Foo.h,

but got an error again.

Foo.h:21:9: Include of non-modular header inside framework module 'Foo'

What should I do to compile successfully?

4

2 Answers 2

2

This seems like an issue with the cocoa pods required for linking React to your project.

Try running pod install in your project directory using terminal and then try to build.

Sign up to request clarification or add additional context in comments.

Comments

0

The linking happens in the hosting app, and not in the framework you've made. That will just need the headers.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.