Cli: Swift support by React Native CLI

Created on 24 May 2019  ·  12Comments  ·  Source: react-native-community/cli

Describe the Feature

Continuing conversation in Kraków w/ @thymikee :

I think React Native Community should head towards embracing Swift.

  • IMO it would be best to set up new RN projects with Swift configured
  • this might be unnacceptable for some since this adds a couple of MB to the binary if supporting iOS <12.2. OTOH this is similar to how Android packages are at least a couple of MB because of JSC being bundled, and it's not that big of a deal

    • it's worth checking out if just configuring Swift support (bridging header and such) is enough to trigger linking Swift even if no Swift files are actually included

  • but we could ask when setting up a project if the user wants to preconfigure Swift (that could include a Swift AppDelegate)
  • at the very least it would be nice if package auto link detected that we’re adding a Swift package and offered to set up necessary Swift support in the app project if not yet set up

I don't know CLI/RN core code very much, but I can offer to help out with the Swift / Xcode setup / CocoaPods bits.

Possible Implementations

Related Issues

feature request ios

All 12 comments

Thanks for bringing that up! cc @orta @alloy

As an (non-default) option that seems reasonable to me.

Adding support to rn-cli will need an extra level of integration testing in RN core because Facebook doesn't build React Native itself as a dynamic framework which will have to be officially supported also. That was a lot of the work which lived in cp-rn-fixer because we use a framework build of React Native in the Artsy app.

Facebook doesn't build React Native itself as a dynamic framework which will have to be officially supported also

Hold on, why do it as a dynamic framework, and not statically linked one? Dynamic frameworks have launch time overhead, and so ever since Swift supports static linking, it's been my impression that it's best to do it that way, unless you specifically want a framework, for, say, app extension sharing

I'm just used to writing dynamic framework, static/dynamic doesn't matter here - the framework aspect is what's important 👍

Hey @radex 👋

That sounds great! I do agree with @orta that it should probably not be the default, because it may require the user to have to know more (as RN isn’t Swift) than they already wanted to know about the native bits.

Heya 👋, is this up for grabs? If so, I'd like to take it!

With RN 0.61.0 out the door with official support for use_frameworks! with Cocoapods, looks like the framework issue @orta mentioned is solved.

I'd go for something like react-native init MySwiftApp --use-swift to enable creating a Swift based RN project. Thoughts?

@glenna we prefer to defer such functionality to custom templates: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template

@thymikee ahh, gotcha! I'll go in that direction, then.

Here's a template: https://github.com/glenna/react-native-template-swifty for use with 0.61.x ✨

Looks like Swift bridging header will be a part of 0.62 release because of Flipper integration:

cc @alloy @radex

Looks like Swift bridging header will be a part of 0.62 release because of Flipper integration:

Not exactly. The template will be made so that it can consume Swift libraries [such as FlipperKit]; if you want to write Swift you’ll still need to introduce a bridging header, but that should happen automatically anyways when adding Swift source, so I think it should be good?

@glenna : Can you write the steps to create that template project using swift???

Was this page helpful?
0 / 5 - 0 ratings