The Kotlin/Swift Interop Playground demonstrates how both simple types (Strings, primitives like Int, Boolean, Char) and custom types (such as data class) can be passed as arguments and returned from function calls across the language boundary.
When calling Kotlin functions from Swift, Kotlin top-level functions are typically accessed via a generated class named after the Kotlin file with a Kt suffix (e.g., TypesKt).
// Kotlin side
fun printInt(intType: Int): Int {
println("Int type: $intType")
return intType
}
fun printString(stringType: String): String {
println("String type: $stringType")
return stringType
}
data class CustomType(val name: String, val surname: String)
fun printCustomType(customType: CustomType): CustomType {
println("Custom type: $customType")
return customType
}
// Swift side
let intType = TypesKt.printInt(intType: 123)
let stringType = TypesKt.printString(stringType: "abc")
let customType = TypesKt.printCustomType(customType: CustomType(name: "Author name", surname: "Author surname"))