Hi, found this channel more relative. A quick ques...
# multiplatform
h
Hi, found this channel more relative. A quick question. Does anyone know the correct 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
p
Singleton is bad anyway, use a Dependency Injection framework if you can
h
The code in the doc not working for me, like I’ve mentioned, got the same crash if I use .shared
p
Humm, 🤔 interesting 🧐, maybe open a ticket if nobody answered.
h
Thanks, I’ll create one, it should be a very common use case.
👍 1