Swift
clear | undo | redo
// Just start typing code...
Kotlin
clear | undo | redo
// Just start typing code...
Usage
Just start typing code! Entering valid Swift code automatically generates corresponding Kotlin code and vice versa. This is work on progress. Last update of the transpiler:
... (Version
...).
Also available as a plugin for Android Studio.
Publications
MOBILESoft 2021
MOBILESoft 2022
Motivation
We assume that during app development a pattern like MVC (model-view-controller) is used. In a multi-platform project (Android and iOS), in particular if the model consists of a significant amount of business logic, it would be advantageous to automatically transpile the Kotlin source code of the model into Swift source code and vice versa. In the best case, we want to achieve that the translated code is syntactically and semantically correct without the need for manual rework. A bidirectional transpiler allows both the Kotlin and the Swift developers in a multi-platform app development project to improve and extend the code of the model using their own prefered programming language and provide the improved and then transpiled code to their colleagues.
Positive Examples
Many features already work fine, at least when used in a rather straightforward way. Positive examples are
- basic concepts like variables, functions, print to console, and string interpolation,
- classes including constructors, inheritance and protocol/interface implementation,
- properties including property observers,
- control structures as well as basic usage of arrays and dictionaries,
- enumerations as well as static functions (Swift) / companion objects (Kotlin),
- structs (Swift) / data classes (Kotlin) as well as Swift tuples when introduced using a typealias,
- subscripts,
- closures (Swift) / lambda expressions (Kotlin) as well as optional binding, and
- switch (Swift) / when (Kotlin) statements as well as inout parameters (Swift) / plain call-by-reference (Kotlin).
In addition, there is a
Negative Examples
However, there is still a lot of work to do. Several things are not supported yet. Negative examples are Swift's guard statement, most methods of arrays and dictionaries, annotations, reliable handling of Swift value types versus Kotlin reference types, abstract classes, and some more.
by Dominik Schultes, Technische Hochschule Mittelhessen