Given I have some code in swift using Kotlin expor...
# kotlin-native
p
Given I have some code in swift using Kotlin exported definitions. It is possible to derive from the ObjClass object the KClass?
Copy code
data class KotlinData(val a: String)

fun <O> createInstance(val classifier: KClass<O>): O
In Swift
Copy code
createInstance(KotlinData.self) <-- Fails as this is not KClass
s
I don’t think so. But this may become possible later.
s
Either this or https://github.com/JetBrains/kotlin-native/blob/9d207ed7b7641f41bd9a78c220bf34c66c38c588/runtime/src/main/cpp/ObjCExport.mm#L946 To be wrapped into
KClassImpl
then. Could you share more details about your case? Do you need similar conversion for protocols?
p
Our case is to write in Kotlin a typed message dispatcher. So one can subscribe by a concrete class reference of (for now Kotlin only classes / interfaces) and additional provide a callback, whenever an instances of that class reference has been published.
Copy code
inline fun <reified O : Any> TypeDispatcher.publish(data: O) = publish(O::class, data)
inline fun <reified O : Any> TypeDispatcher.subscribe(noinline callback: (O) -> Unit, on: DispatchQueue = mainQueue) = subscribe(O::class, callback, on)
inline fun <reified O : Any> TypeDispatcher.unsubscribe(noinline callback: (O) -> Unit) = unsubscribe(O::class, callback)
o
p
This really looks counter-intuitiv