pererikbergman
10/14/2021, 2:21 PMobject 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?Trevor Stone
10/14/2021, 2:46 PMactual/expect
pererikbergman
10/14/2021, 3:04 PMMejdi
10/14/2021, 4:34 PM@ThreadLocal
on iOS (KMM) by default all singletons properties are freezed by default..so you cant mutate them. One way to avoid it is to mark it @ThreadLocal
which means every thread will get its own copy and will be able to mutate it. Should not be any issue if you dont have multithreading.pererikbergman
10/15/2021, 1:36 AMMejdi
10/15/2021, 5:11 AMpererikbergman
10/15/2021, 10:56 AM