Is there a way to grab a `KClass` of an object def...
# multiplatform
k
Is there a way to grab a
KClass
of an object defined in Kotlin from Swift? I have a function defined in Kotlin that has an argument
type: KClass
and I need a way to call that function from Swift, but not sure how to pass in the type.
s
Do I understand correctly that you need to get a
KClass
of an instance? Like in
fun getClassOf(obj: Any) = obj::class
?
k
I believe that is indeed what I needed. I'll let you know if this worked out.
Okay so the problem I am having is I don't have an instance of the type. I am essentially trying to write
get(type: Foo::class)
in Swift. The kotlin function definition would be
fun <T> get(type: KClass<T>): T
. In the context which I am using it, I have a global factory to inject instances of a presenter thus I don't have the instance just the class that I want an instance of.
s
Is
Foo
a class or an interface?
k
Foo
would be an abstract class defined in Kotlin.
s
We consider implementing this feature later.
k
I can get around this issue by creating a factory method in the companion object of the abstract class instead of creating a centralized factory object.