I try to use in Kotlin Multiplatform XCFramework with Swift code.
I have a protocol with extension for default implementation of this protocol
@objc protocol Greeting {
var something: String { get }
}
extension Greeting {
var something: String {
return "Hello from Swift"
}
}
And in Platform.kt I'm writing
class GreetingImpl: NSObject(), GreetingProtocol {
override fun something(): String {
return (this as GreetingProtocol).something()
}
}
actual class Platform actual constructor() {
val object = GreetingImpl()
val value = object.something() //Application builds but falls here
}
How can I use Swift protocol default implementation in Kotlin Multiplatform?
As far as I can see, there are two main problems:
@objc
annotation. While this is a Swift-side limitation, this prevents Kotlin from providing full interoperability(Kotlin/Native supports no direct interoperability with Swift, only through Objective-C [docs]).So, I would say there is no option to use Swift protocol default implementation in Kotlin Multiplatform.