Hey all,
I have a big upcoming project and I am considering going KMM so I have been testing, playing learning for the last month or so.
Most of my issues been solve no problem, but I can’t manage to find a solution for this:
I want to be able to wrap any arbitrary library in androidApp and iosApp and inject it into shared, I tried to create a singleton where I would store this wrapper with no success.
In commonMain I want to do this:
object MySingleton {
var myInterface: MyInterface? = null
fun hello(msg:String) {
myInterface?.hello(msg)
}
}
interface MyInterface {
fun hello(msg: String)
}
And then in androidApp
MySingleton.myInterface = object : MyInterface {
override fun hello(msg: String) {
// do some magic
}
}
And in iOS something like this:
class MyInterfaceImpl : MyInterface {
func hello(msg: String) {
// do some magic
}
}
MySingleton.shared.myInterface = MyInterfaceImpl()
But it just crashes on iOS, no clear error message as well.
Anyone have any suggestion on how to do this?