-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transition to Swift #253
Comments
Linking to What don't you like about React-Native => Swift not being the default language for iOS |
👋
In particular, I'll quote here the response:
I haven't heard anything on this topic anywhere so my assumption is that the situation hasn't changed. Because of the two above reasons I think this issue should be closed. |
EDIT: I capped. 🧢 In many cases Swift is faster than Objective-C. |
With Swift 5+ there are plenty of scenarios where Swift is now faster than Objective-C. With every new Swift release this will improve in favor of Swift. For performance critical code a lot of companies still use C(++). Note that in my post I'm proposing a slow transition to Swift. If there are a few specific scenarios where it still makes more sense to use Objective-C, then use Objective-C for that. The use of Swift doesn't cancel out the use of Objective-C. I just find it very odd that when you create a new React-Native project that it creates the AppDelegate etc. in Objective-C instead of Swift. I think it would also improve the quality of the community components if it is easier to set those up with Swift and Kotlin. |
That's definitely true. I had a pretty hard time creating my native modules, since there is little to no documentation for this, especially not for Swift. Also Swift doesn't support Macros, which requires us to have Objective-C headers and Bridges in every native module. Probably the biggest problem is that Swift doesn't easily interop with C++, which is where React Native is heading with the Re-Architecture. tbh I'm not really up to date with the current performance differences between Objective-C and Swift 5, I've just always thought Objective-C had less overhead and was a better choice if speed really matters a lot. |
Yes, that's one of my main concerns and why I decided to write this proposal. Right now it is kinda difficult to get started with Swift and Kotlin on React-Native. I think that it will hurt React-Native's adoption at some point. This project has helped me to set up a few RN libraries:
Swift 5 is performing a lot better than Swift 3. The performance differences are getting smaller with every release. It is unfortunate that Swift sometimes performs worse than Objective-C because of bridging in order to be compatible with Objective-C (examples: In the end there's no reason why a static language like Swift shouldn't outperform a dynamic language like Objective-C. You can never apply the same level of compiler optimization to a dynamic language. |
I believe the biggest blocker here is that Swift does not smoothly interop with C++ (which is the direction React Native is moving with the re-architecture), while Objective-C does. (Objective-C++, |
I think there are two different discussion points in this issue:
I'd like to add mine and my team's 2c around point number 2: Ideally we'd like to transition our React Native app to pure Swift. In our case this essentially means converting AppDelegate to Swift (and other stuff the OP mentions). This is fine for us to do but it presents a challenge in staying up to date with new React Native versions - we'll need to translate the diff produced by https://github.com/react-native-community/rn-diff-purge to Swift on every release. I believe teams would prefer to have their AppDelegate written in Swift and right now the fact that there doesn't exist a Swift template for react native is blocking them or causing duplicated work across the react native ecosystem. My proposal is: Convert the react native official template to be Swift-first and release this in a new react native version. Alternative, maintain two official templates: one swift-first and one ObjectiveC-first. This may be required anyway to initially introduce the swift version to the community while gradually phasing out the ObjectiveC version. |
Apple announced C++ Interoperability in Swift 5.9 at WWDC 2023. Should we reconsider the transition to Swift?
|
I think we should at least start considering turning the templates over (Like the work done on the Kotlin side of things). Admittedly Swift 5.9 does require Xcode 15, which some users might not be using just yet, but Apple will enforce it's use from April 2024. so it's not that big of a blocker. |
Introduction
When development on React-Native started, Objective-C was the primary language for all iOS apps. On June 2, 2014, a little under a year before the first public release of React-Native, Apple's new programming language Swift was introduced to the world.
The first few versions of Swift were not ready for production apps. New releases often introduced code breaking changes and I think we all have "fond" memories of the Xcode SourceKit crashes and other stability issues.
Fast forward to March 2019, Swift 5 was introduced with ABI stability. Many developers have now adopted the language and Apple is pushing the language forward with a new Swift-only UI framework called SwiftUI. During WWDC 2020 we learn that parts of MacOS Big Sur (for example the new control center) are implemented with SwiftUI.
Clearly Objective-C is moving into the background and the path forward is Swift. My proposal for React-Native would be to start moving into the same direction.
Details
When you create a new React-Native project, you are greeted by an Objective-C project. With some work you can convert the
AppDelegate
and other classes to Swift and you'll have to figure out how to get the Podfile properly configured for Swift <=> Objective-C interoperability.This isn't a great experience for new developers starting with React-Native, nor for developers that already have a native app written in Swift and that want to transition to a multi-platform React-Native app.
When it comes to device support, the first iOS version able to run Swift apps was iOS 7. The minimum requirement for React-Native nowadays is iOS 10, therefor Swift support is not a problem.
But why Swift? I think there could be a lot to gain from the safety features that are built right into the Swift language. Code written in Swift is often shorter and uses a modern syntax that reduces code complexity.
Discussion points
(we could start a similar proposal for Android for Kotlin)
The text was updated successfully, but these errors were encountered: