frostney / react-native-create-library

:notebook: Command line tool to create a React Native library with a single command
MIT License
1.45k stars 113 forks source link

Support of Swift? #30

Open wandonye opened 7 years ago

wandonye commented 7 years ago

I added a swift class, then it complains:

Check dependencies
Swift is not supported for static libraries.

when I click run.

ananevam commented 7 years ago

+1

maicki commented 6 years ago

Unfortunately, currently it is not possible to use Swift in a static library. react-native-create-library would have to create a dynamic framework, what would add a lot of overhead to the startup time of your app if you link a lot of dynamic libs. Furthermore currently react-native link does not support dynamic frameworks.

That said you can still use Swift in a React Native library, if you integrate the library via CococaPods. CocoaPods should automatically create a dynamic lib from your React Native library and setup your Xcode project the right way, like e.g. native-navigation (https://github.com/airbnb/native-navigation) does as it is Swift only too.

The cool thing is that if you use react-native-create-library to bootstrap the library you should also get a podspec file you can use to integrate via CocoaPods.

Elf2707 commented 6 years ago

I found out interesting fact. If I add even empty swift file to main project I get this bunch of settings: 2018-05-08 17 24 28

then I create bridging file SomeName-Bridging-Header.h and setup property Objective-C-Bridging-Header to refer to this file. And after that I can use swift code in the static library in the way how it describes here https://facebook.github.io/react-native/docs/native-modules-ios.html (Making Objective-C Manager file for exposing Swift module from the library) It builds and links.

Im not so good with Xcode and don't know if there is a way to get those bunch of settings without creating empty swift file.

Elf2707 commented 6 years ago

Funny :) but I found description of the same hack on the bottom of the doc I put the link before https://facebook.github.io/react-native/docs/native-modules-ios.html

So it means there are no other ways to get those settings in Xcode than to add a empty swift file to main project. And this will allow to use swift in static libraries.

acollazomayer commented 6 years ago

@Elf2707 Im trying to do the same that you did however i get this error in my swift code 'AVStreamingKeyDeliveryPersistentContentKeyType' is only available on iOS 9.0 or newer is there a way to set the iOS deployment version in the static library

b-asaf commented 5 years ago

I create library using this package and inside it I did the following:

  1. Migrate the objective-c files to swift file
  2. Create objective-c file to export the method I implemented in the swift file (currently only 1)
  3. Create libName-Bridging-Header file

The steps above were inside the newly created library. When I build it - it failed. But according to issue #87, the library can't be "standalone" project.

I linked the library to the main app (written in react-native v0.57.8):

  1. The library is in the Libraries group of the main app
  2. library.a is in the Link Binar With Libraries' list inBuild Phases` section

But the build keep failing :( The settings that @Elf2707 mentioned are not visible to me in the main app: image

Is the only option for me to write library in iOS native is to use objective-c?

iyegoroff commented 5 years ago

You can use my https://github.com/iyegoroff/make-react-native-package CLI tool to scaffold a react-native package with Swift/Kotlin/Typescript