talknagish / react-native-turbo-starter

React 0.68+ Turbo Module starter using codegen with typescript for Objective-C and Java/Kotlin with C++ shared library. 🚀🚀🚀
MIT License
381 stars 27 forks source link

Bridge C++ to Swift through Objective-C #20

Open gabimoncha opened 2 years ago

gabimoncha commented 2 years ago

I understand that it's pretty impossible to call call C++ from Swift, but Swift could call ObjC methods. In this article there is an example on how to use ObjC to bridge C++ to Swift and might be a good start to make this library support it too

https://anuragajwani.medium.com/how-to-consume-c-code-in-swift-b4d64a04e989

alon7 commented 2 years ago

Thanks for sharing, @gabrielmoncea. Codegen generates .mm files, and I couldn't find an easy way to implement the protocol of the generated code in Swift. Especially since there's a function you must call from our own .mm file that is entirely c++ (the JSI binding itself).

I would love to see a proof of concept with swift + nice binding but couldn't get one working by myself (invested about 2-3 hours in trying and making it happen)