DEV Community

Cover image for Swift Klib Gradle Plugin is out
Evgeny Khokhlov
Evgeny Khokhlov

Posted on

Swift Klib Gradle Plugin is out

I am thrilled to announce the release of new Gradle plugin for Kotlin Multiplatform Mobile development - Swift Klib! It designed to make it easier for you to integrate and manage Swift sources in your KMM shared module. With Swift Klib, you can now easily include your Swift source files in your KMM shared module and access them in Kotlin via cinterop for iOS targets.

Use cases

Although Swift Klib was originally created to access Swift-only Libraries in Kotlin, it is also ideal for several other things. Here are a few:

Learning how Swift <-> Kotlin interoperability works

You can get hands-on experience with the interoperability of Swift and Kotlin. You can start with simple examples, such as the Hello World example in the plugin's repo, and observe how bindings are created in Kotlin. Then you can make changes, add more code, and observe the results.

Accessing Swift-only libraries

There is no direct interoperability between Kotlin and modern Swift libraries without an Objective-C API, such as ActivityKit, CryptoKit, Combine, etc. Swift Klib fills this gap by allowing you to easily create Kotlin-friendly wrappers in Swift and access them in your Kotlin code.

Creating a Kotlin-Friendly Swift API

Kotlin uses Objective-C APIs for libraries, that's why the automatic bindings for iOS libraries can produce an API that may be unfamiliar to those familiar with the Swift API. For example, the Swift UserDefaults.standard translates to NSUserDefaults.standardUserDefaults in Kotlin. With Swift Klib, you can create wrappers for the API you want to use and have full control over it.

I hope you enjoy using Swift Klib and can't wait to see what you'll create with it. If you have any questions or feedback, please don't hesitate to create an issue on GitHub.

Happy coding!

Oldest comments (0)