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'
I ran react-native link
, but nothing changed.
React.xcodeproj
to Foo
project and add libReact.a
to Link Binary With Libraries
.$(SRCROOT)/../node_modules/react-native/React
to Header Search Paths
.But it doesn't work. The error still remains.
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.
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'
The main difference between React Native and Swift is that React Native is best for cross-platform development, while Swift is for building iOS apps. Thus, you may develop an Android application in Java or Kotlin, for example, and choose Swift and Objective-C for iOS only.
Building a React Native app on iOS with XcodeYou can build a React Native app either using the React Native CLI, which allows you to run build commands from your terminal, or Xcode.
Mostly React Native code is written with Objective-C because React Native core uses Yoga lib for layout that works better bridging with Objective-C because is written in C++. But how we can see on documentation we also can bridge our application with Swift to use these functionalities.
Swift is future-proof and can be extended with new features as needed. Thus, such apps are typically easier to scale. Less coding. Swift is very concise, which means you need less code to perform the same task, as compared to React Native.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With