It's either a bad simulator, or it's simulating bad Swift. Maybe both.
Welcome to the repository for our Codelab, Close the Platform Gap with the "Bad Swift Simulator". The code in this repository is meant to showcase issues with Kotlin API when used from Swift. But if you're coming from Android, you probably aren't that familiar with Swift. So instead we'll show you in native Kotlin!
The Bad Swift Simulator explores modern language features, that are present in both Swift and Kotlin, but get lost in translation.
The features currently showcased are:
- Enums
- Sealed Interfaces (also applies to sealed classes)
- Global Functions (also applies to global properties)
- Suspend Functions
- Coroutine Flows
- Default Arguments
- Function Generics
There are more oddities that happen when Kotlin is exposed to Swift, and we'll cover those in the future.
To get ready for the Codelab, go through the list below, and make sure your computer is set up correctly.
- Latest stable Android Studio, or IntelliJ IDEA (with Android plugin enabled)
- Fairly latest Android SDK installation
- Android emulator (AVD), or an Android phone with USB debugging enabled (don't forget to bring a cable)
- A JVM capable of running Kotlin 1.9.23 and Gradle 8.4 or newer (JVM 11 or 17 is preferred)
Bad Swift Simulator is mostly a regular Android project, but it does contain a Kotlin Multiplatform portion. If you wish to try out that part too, make sure you have Xcode 15.1 or newer installed. Then use JetBrains' kdoctor to ensure you have a functional KMP installation.
Otherwise, open settings.gradle.kts and comment out the last two modules, :kmp:regular and :kmp:skie.
To get started, clone this repository on your machine (or download the source zip from GitHub).
git clone https://github.com/touchlab/BadSwiftSimulatorOnce cloned,
open the project in your IDE of choice (as long as it's either Android Studio, or IntelliJ IDEA).
Wait for Gradle to complete sync and run the :app:good on an emulator.
Important
Make sure to run the :app:good on an emulator as soon as possible.
Although the project is small, it still needs to download Android and KMP dependencies.
Tip
If you wish to try the iOS side as well,
open ios/SDKSample.xcodeproj in Xcode.
Wait for Xcode to complete indexing and then run either SKIESample or KotlinSample scheme on a simulator.