Hi, a quick question. Does anyone know the best practice of Singleton in Kotlin multiplatform? I have something like
Copy code
object MyClass {
var myValue:xxx
}
defined in the kotlin module. I’m trying to access it in iOS with something like`MyClass().myValue`, but my app crashes immediately with error: Thread 1: EXC_BAD_ACCESS (code=1, address=0xa8). It also crashes with the same message if I use
MyClass.shared.myValue
k
Kirill Grouchnikov
05/08/2024, 2:01 AM
What about just
MyClass.myValue
h
Huanzhi Zhang
05/08/2024, 4:38 AM
the build will fail: “Instance member ‘myValue’ cannot be used on type ‘MyClass’;…”