Brian Stanek
02/05/2020, 1:35 PMClass<SomeProtocol> that it can internally instantiate when needed.
In kotlin I can create a class that conforms to SomeProtocol - but I don’t know how to (or if it’s even possible to) get an “Objective-C class” from that class.
I tried passing it as MyClass::class, but the compiler complains that it got a KClass<MyClass> but was expecting a SomeProtocol? - which isn’t quite right, because the API I’m calling expects a class, not an instance.
Using MyClass::class as SomeProtocol appeases the compiler, but results in a TypeCastException at runtime.
Is there anything analogous to KotlinClass::class.java in the native world?Artyom Degtyarev [JB]
02/05/2020, 2:15 PMBrian Stanek
02/05/2020, 5:18 PMClass type.
Unfortunately, I couldn't figure out how to finish things in kotlin - the compiler still complains that it is expecting a SomeProtocol?, but now I'm passing in an ObjCClass. I couldn't find any cast that works (and I'm not even sure how to represent that type in kotlin, an ObjCClass whose instances conform to SomeProtocol).
I ended up adding an objective-c .def file with a function that takes in a Class and then passes that through to the API that expects a Class<SomeProtocol> .
Not as clean as I'd hoped, but it works, and it's a simple workaround.