Kotlin Multiplatform: Running Swift code from inside Kotlin

preview_player
Показать описание
Want to call native Swift code from Kotlin in your Kotlin Multiplatform (KMP) project? Whether you're using Compose Multiplatform or just working with shared KMP business logic, this video walks you through creating a clean Swift–Kotlin interop layer.

✅ You'll learn:

How to use the expect/actual mechanism for platform-specific logic
How to define an interface in Kotlin and implement it in Swift
How to call Swift code directly from Kotlin using NativeResponseProvider
How to set up the interop bridge between KMP and iOS in Xcode

🧠 Works with or without Jetpack Compose!
Perfect for Kotlin developers targeting both Android and iOS.

📦 GitHub source code:

📄 Full article with code snippets:

🔔 Subscribe for more Kotlin & Android dev tutorials!

00:00 Introduction
00:31 Starter Code
02:11 Defining Interface in Kotlin
02:54 Implementing the Interface in Swift
04:29 Creating Reference Variable
05:17 Assigning Variable to Swift Class Instance

#KotlinMultiplatform #SwiftInterop #ComposeMultiplatform #iOSDevelopment #JetpackCompose #MobileDevelopment #KMP #AndroidDev #Kotlin
Комментарии
Автор

very helpful please make a video to use native swift views from kotlin

techxyz
Автор

So did I get this right? If you just want to have kotlin code that only executes within its supposed environment, e.g. special use cases for iOS users that dont apply to android users, you can use the expect/actual mechanism. So basically just a neat way to split platform specific code into separate modules. But if you need to access the platform specific resources and need to rely on the libraries only provided for that platform, e.g. system service registration or file picker opening, you need to go through interfaces to connect the shared kotlin code with the native side of the app?

gurkengerd
Автор

Is there any way to do achieve that ? E.g. can we call direct class in kotlin file ( like we can do for kotlin classes in xcode project ) or something like that.

Nick-cxrs
Автор

Wow, I didn't know that was actually possible. Thanks for sharing!

fernandoobregon
welcome to shbcf.ru