-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Update the iOS template from Obj-C to Swift #41896
Conversation
Hi @TheRogue76! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Base commit: 86df742 |
The failed test had simply timed out. And i signed the CLA. Let's hope it picks it up correctly. |
Does anything depend on the hello world template being created in Obj-C? I think it's a good approach. Could you summarize a bit more on what might break and how to mitigate the risk? |
I don't believe it does, since it is the top of the app and since it consumes everything, any dependency on it might cause a dependency cycle, but i also admit i am not aware of all the details on the iOS side of the repo (Please feel free to add anyone you think might know more). I did double check that the bundle URLs were the correct values for debug/release. Only things i felt were noteworthy were:
The imports might look a bit weird (For example
|
@@ -0,0 +1,8 @@ | |||
import UIKit | |||
|
|||
UIApplicationMain( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed, you can annotate AppDelegate
with @main
. Check newly generated project from Xcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved under 92a1ae0. I wanted to keep the file structures the same for review, but if we are committing to use Swift, might as well take advantage of it. And @main
was introduced in 5.3, so pretty much everyone should have it.
Hi @TheRogue76, thanks for submitting the PR. On the technical side, I can tell you already that there are several things missing: for example, there are no changes to the cocoapod infra to pass over all the Cxx flags that we pass and we would have to pass them to Swift as well, in the form of I don't want to discourage you, as this is an amazing starting point. ContextTo share more context on the complexity of this change, changing from Objective-C to Swift is not as straightforward as from Java to Kotlin, unfortunately. I tried myself the migration a couple of time in the past and always encountered issues which would have taken a non negligible amount of time to be fixed.
Moreover, there are several subtleties that we need to consider. Just to mention some of them:
Talking about the auxiliary tools:
Next StepsSo, yeah, although this is a great starting point, I think that a better approach would be to:
|
Hey @cipolleschi All fair. I assumed that since the Template itself doesn't interact directly with those bits (just RCTDelegate) and is simply there for the consumption of OSS, we could simply circumvent the issue altogether and transition over the delegate itself, but if it's going to propagate I suppose that won't work. What sort of help can I provide on the RFC side? |
I haven't read the RFC yet, but as I can see is from 2020... and multiple things have changed since then! 😄 So, I'd probably start by taking the RFC and by rewriting it. This will help to remove the bits that are not valid anymore and to add all the considerations I added above. The second part of the RFC would list all the changes (at a high-level) that we need to apply:
This helps in identifying dependencies and make sure we can involve all the people that might have opinions or knowledge about it. The last part should be related to Adoption and Communication: what users should expect when a new version of React Native with this changes is released. This probably implies writing a migration guide from Obj-C to Swift. As a reference for the RFC structure, you can take the Wide Gamut RFC. |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
1 similar comment
This PR was closed because it has been stalled for 7 days with no activity. |
Summary:
Before this PR gets controversial, i just want to preface it by saying that i understand that moving EVERYTHING over from Obj-C to Swift is not viable, and I understand why it has not been done till now, but i think we can have a nice path forward if we just update the bits that are facing OSS, and leave everything else for later.
As mentioned in react-native-community/discussions-and-proposals#253 (comment) Apple will enforce Xcode 15 (Swift 5.9) from around April of 2024 for sending new apps to appstore connect, so the stuff we will need to add support for directly wiring up the C++ sections of RN to the Swift parts can be migrated soon, but that is not the scope of this PR.
This PR is inspired by the recent migration of the Android Template from Java to Kotlin. In that migration, we updated the tests, and the primary template, but we left everything else untouched.
The reasoning is also similar to that of the Android migration: Most developers would prefer to create the native bits of their apps using more modern languages. These languages are easier to debug and problems in them can be discovered much quicker.
The update to the template also ensures the users who have done these migrations on their own that they can still use the react native upgrade helper to update their apps every time a new version of React Native is released.
The end goal is to at least have a conversation, and see how viable it is to do this. I tried this on a test repository before hand to make sure it worked fine in both debug mode and release
Changelog:
[IOS] [BREAKING] - update the iOS app template from Objective-C to Swift. Also add the DEBUG Active compilation conditions flag for the Swift compiler so:
is read correctly.
Test Plan:
My test repository:
https://github.com/TheRogue76/React-Native-Template-With-Swift
Screenshot:
And the CI being green