· 4 min read Posted by Tadeas Kriz
Xcode-Kotlin 2.0 Release
Today we have big news for Kotlin Multiplatform debugging. We’re releasing xcode-kotlin 2.0 with major improvements such as:
- Vastly improved debugging performance (up to 5 times faster).
- Expanded information for each frame variable.
- Works in Swift, Kotlin and Objective-C code.
- Built-in support for
List
andMap
with more coming (e.g.StateFlow
,Set
).
Don’t miss out, xcode-kotlin is free, Open Source and available through Homebrew.
Get Started
To install xcode-kotlin, run:
brew install xcode-kotlin
If you already have it installed, you can upgrade from your current version by running:
brew update && brew upgrade xcode-kotlin
After a successful installation,
you’ll have xcode-kotlin
CLI available in your terminal.
Go head and install the Xcode plugin by running:
xcode-kotlin install
Some versions of Xcode don’t set up in time and the installation may time out. If that happens, rerun the installation command.
Last step is to open Xcode, add Kotlin sources to your project, and place a breakpoint in the Kotlin code. If you can’t place a breakpoint, or there’s no code highlighting, try rerunning the installation command.
What’s New
xcode-kotlin has been with us for a long time and is a must-have for debugging Kotlin Multiplatform code from Xcode. We’ve always been using the debugger script from Kotlin, but it was never meant for interactive debugging in Xcode and therefore was limited and rather slow.
Which is why we dug deep, researched LLDB scripting, and rumaged through the LLDB codebase. After multiple dead-ends, we’ve had a breaktrough. The result is a new LLDB script that’s all but written from the ground up.
One of the big changes is the performance. We’ve changed how debug data about your Kotlin instances is collected, which has resulted in up to 5 times faster frame variable resolution. It also gives us more information about each variable, allowing us to add more features in the future.
Thanks to the performance headroom, we’ve improved the type summaries for frame variables. That means you’ll see more information about your Kotlin instances, similar to what you’re used to when debugging Kotlin/JVM code in IntelliJ IDEA and Android Studio.
We’ve also been able to add custom handling for certain Kotlin types.
Currently we handle String
, Array
, List
and Map
differently than other types.
This allows us to show tailored information about these types,
and hide internal details that are not relevant to you.
Lastly we’ve added support for Kotlin frame variables in Swift and Objective-C code. Due to the way Kotlin Multiplatform works, Kotlin classes get wrapped in Objective-C bridging classes. The original LLDB script wasn’t handling the bridging classes, so you wouldn’t see details of Kotlin instances in Swift or Objective-C code. This has been fixed in the new script, which shows you the same summary and fields as in Kotlin code.
Let’s take a look at the new summaries in action.
In the first screenshot,
we’re stopped in Kotlin code.
In the botom of the screen,
you can see the new summaries and fields.
As you can see,
List
and Map
show their contents directly,
without exposing the internal details.
In the second screenshot, we’re stopped in Swift code. Notice the summary and fields are the same as in Kotlin code, even though the instance is a Kotlin class wrapped in an Objective-C bridging class.
In the last screenshot, we’re stopped in Objective-C code. Although most of us don’t write Objective-C code anymore, it’s good to have the same support for it. As you can see, the summary and fields are the same as in Kotlin and Swift code.
What’s Next
This is a big step forward for Kotlin Multiplatform debugging in Xcode. Thanks to the changes we made in the LLDB script, we now have a solid foundation for future improvements. But we don’t want to build in a vacuum.
Instead we’d love to hear from you, what’s missing in your debugging workflow? What would you like to see in the next version of xcode-kotlin? Let us know by creating a new discussion in the xcode-kotlin repository.