· 3 min read Posted by Touchlab

Livestream: Close the Swift/Kotlin Platform Gap

Calling Kotlin Multiplatform from Swift can be a painful experience. Kotlin engineers new to KMP rarely understand the issues. The "Bad Swift Simulation" helps Kotlin engineers "feel the pain" by replicating the experience directly in Kotlin. With that experience, understanding how to fix the situation, and why you need to, is much simpler.
Choo Yut Shing https://www.flickr.com/photos/25802865@N08/42929925641/
Credit: Choo Yut Shing https://www.flickr.com/photos/25802865@N08/42929925641/

Overview

KMP is about to hit the main stream. The runtime has been stable for years, but JetBrains declared the full platform stable in 2024. Google’s Android team now endorses KMP for native mobile.

If you look at the recommend tools for KMP in the Android post above, you’ll notice SKIE:

Additionally, SKIE facilitates the use of modern types and coroutines on iOS

Watch this live stream to learn why SKIE is a critical tool for iOS/KMP development!

The Kotlin compiler will take any valid Kotlin and export it to Swift, but a lot of Kotlin’s modern features are lost along the way. For any serious native mobile KMP effort, understanding this issue and how to improve the situation is critical.

There is a common misconception that Android developers can simply “start writing KMP” and sharing code with the iOS team. This is generally not true. Most Kotlin devs don’t really “know” Swift. Most have had some intro-level introduction to Swift, but don’t really understand Swift types and conventions.

Touchlab has been talking about this issue for some time, and we publish the tool SKIE to bridge Kotlin to Swift in a way that preserves Kotlin’s expressiveness. However, explaining how SKIE improves the Swift developer experience is difficult if you’re not a Swift expert.

We’ve come up with a new idea.

Bad Swift Simulation

For an audience of Kotlin experts, rather than explain why the Swift output is bad, you’ll get to experience it directly. The Bad Swift Simulation takes a Kotlin API, with all of Kotlin’s modern features, then simply removes them. The task, then, is to rewrite the Kotlin code that calls the API without those features available.

It’s not a perfect simulation. For all of their reported syntactic similarity, they are very different languages. For example, you can’t reproduce the “lack of structs” in a way that really gets the point across. But there’s plenty of other stuff that Swift engineers are forced to live without. Unnecessarily.

Fix it

With that fresh knowledge in mind, you’ll learn how to address the situation. A combination of tools, Kotlin best-practice, and using SKIE to bridge major, modern Kotlin types to their Swift equivalents.

Being able to write good KMP code, providing not just Swift-interop, but Swift Fluency, is a critical skill for any serious KMP developer working with a native mobile team. Our live stream video is a quick introduction to the basics, but provides a much-needed foundation for developers and teams looking to adopt KMP at scale.