我正在 iOS 上对 Kotlin Native 进行一些试验,我想尝试的一件事是拥有 Kotlin 定义的接口的 Swift 实现。但是,当我尝试将该 Swift 对象传回 Kotlin 代码时,我最终崩溃了。
我正在使用 kotlin gradle 插件版本 1.2.30 和 kotlin 本机版本 0.6.1
下面是一个最小的例子。Kotlin 代码正在编译为名为 KotlinCommon 的框架,然后将其包含在 xcode 项目中。
演示类.kt
class DemoClass {
fun process(dependency: Dependency) {
dependency.foo()
}
}
interface Dependency {
fun foo()
}
SwiftDependency.swift
import KotlinCommon
class SwiftDependency : KotlinCommonDependency {
func foo() {
NSLog("hello")
}
}
然后,从我的 iOS UI 我尝试运行
let module = KotlinCommonDemoClass()
let dependency = SwiftDependency()
module.process(dependency: dependency)
第三行导致崩溃并出现以下错误:
*** NSForwarding: warning: object 0x101858d20 of class 'KotlinNativeDemo.SwiftDependency' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[KotlinNativeDemo.SwiftDependency toKotlin:]
Kotlin Native 不支持这个用例吗?还是我配置错误?