Gryphon is a program that translates Swift code into Kotlin code. It was created to enable mobile app developers to share parts of an iOS app's codebase with Android.
- Risk-free. Stop using Gryphon whenever you want - you'll still be able to read and understand your Kotlin code, even the computer-generated parts.
- No editing needed. Translated Kotlin files work the same as the Swift files they came from.
- Xcode integration. Translate your iOS code to Android, compile the Android app, and see Kotlin's errors and warnings in the Swift lines that originated them - all without leaving Xcode.
- Custom-made. Use special comments and templates to customize your Kotlin translation, and use any platform-specific features you want - even in translated source files.
Gryphon is now in preview! 🎉
This means the main systems and ideas have already been implemented - for instance, it's been translating a complete version of its own codebase for a while now. However, users often find new bugs to be fixed. If that's the case, feel free to report a new issue on GitHub.
You can also check out the currently supported translations for the Swift standard library here.
Gryphon supports both macOS and Linux. You can install it with:
Use Homebrew to install Gryphon and its dependencies automatically:
$ brew install vinivendra/gryphon/gryphon
Use Mint to install Gryphon using the Swift package manager:
$ mint install vinivendra/Gryphon
Try it out on GitPod before downloading:
Clone the repo run the installation script:
$ git clone https://github.com/vinivendra/Gryphon.git
$ cd Gryphon
$ ./Scripts/install.sh
Install it in a Docker container:
$ git clone https://github.com/vinivendra/Gryphon.git
$ cd Gryphon
$ docker build -t gryphon .
$ docker run -it --rm --privileged -v /absolute/path/to/current/directory/:/app/Gryphon gryphon
# ./Scripts/install.sh
Check out the Tutorial to get started. It covers the basic information needed to begin using Gryphon, whether you want to translate command line programs, translate a new iOS app to Android, or add Gryphon to an existing app.
There are also more advanced guides on using collections, using translation comments, and using templates
Gryphon is a command line application that can translate Swift code into Kotlin code. It was especially designed to enable app developers to translate platform-independent parts of their iOS apps into code they can use in their Android apps.
Gryphon's output code is meant to behave just like the input code that created it. It's still possible technically to generate Kotlin code that doesn't compile - for instance, if you try to translate unsupported Swift features, or if there's a bug - but as a rule, you should be able to translate, compile and run supported code without the need for post-translation edits.
One of Gryphon's main goals is to make sure translated code can be understood by human beings. As a rule, if you understand the input Swift code, you should also be able to understand the translated Kotlin code - if you don't, feel free to file a bug report.
This is done within some realistic constraints: the priority is that the translated code has to behave correctly, for instance. Gryphon attempts to find a "reasonably understandable Kotlin" middle ground somewhere between "machine-code-like Kotlin" and "perfectly idiomatic Kotlin".
Gryphon's support for Swift features is constantly evolving. It is currently capable of translating many of the main features one might expect - classes, structs, enums, closures, extensions, protocols, etc - enough that it currently translates around 97% of a version of its own codebase (the other 3% are platform-specific files). Some Swift features are just waiting to be implemented, while others can't be translated to Kotlin and may never be supported.
Gryphon currently supports Swift 5.2 to 5.5. It will use whatever Swift version was used to build it, so if you build the Gryphon binary using Swift 5.5 then that's the version it will assume all your Swift code is in. You can find out which Swift version your Gryphon binary uses by running gryphon --version
.
Due to some technical limitations, only Swift 5.3, 5.4 and 5.5 are being tested in the latest versions of Gryphon. If you have any difficulties with Swift 5.2, please let us know.
Yes - but it will need some adaptations (though probably less than your average multiplatform framework). This depends on your application - how similar app's architecture is to its Android counterpart, how often your code uses Swift features unsupported by Gryphon, etc.
It's worth noting that, like other transpilers for app development, Gryphon is best suited for translating platform-independent logic code. There's currently no support for translating calls to UIKit, for instance - and there's no telling if that will happen someday.
It is recommended that you start by translating only a few platform-independent parts of your code, adding new files incrementally. It might help to use architectures with clear separations between UI code and logic code - like MVP and MVC to separate the code that can be translated. For more information, check out Adding Gryphon to an existing app.
Yes. While Gryphon's main focus is on iOS-to-Android support, it is primarily a Swift to Kotlin translator, and it doesn't require anything iOS-specific to run. You can use it on Linux to translate command line tools, for example. Even Gryphon's own source code can be translated, and that's just a command-line tool with nothing iOS-related.
Probably not. The challenges involved in translating Swift code into Kotlin are very specific for these two languages. Translating Kotlin into Swift would require a new front-end for Kotlin, a new back-end for Swift, and all-new logic in the middle to turn one into the other - basically, a whole new Gryphon. The same goes for other combinations of languages.
Thanks for the offer!
If you want to suggest a way to improve Gryphon, feel free to open a new issue. All bug reports and feature requests are welcome and encouraged - we can't fix it if we don't know about it!
If you would like to contribute directly, first check out the contributor's guide to learn to set up your environment. Then, if you're looking for inspiration, take a look at some good first issues (if you're new to Gryphon) or the beginner-friendly first timers only (if you're new to open source) - or, if you already know what you want to do, open an issue and let's talk about it.
If you're going to contribute, you should probably read the code of conduct too.