Skip to content

Transition to Swift #253

@yvbeek

Description

@yvbeek

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

  • What are the specific Objective-C features that React-Native is using (things like macros)?
  • What are up- and downsides of slowly transitioning the codebase to Swift?
  • What would be the best way to move towards a Swift codebase (new files in Swift, patch some code with extensions)?
  • How can we make React-Native more accessible to Swift developers?
  • How can we make it easier to create React-Native community packages in Swift?

(we could start a similar proposal for Android for Kotlin)

Metadata

Metadata

Assignees

No one assigned

    Labels

    🗣 DiscussionThis label identifies an ongoing discussion on a subject

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions