Facing weird issue with `object` in iOS app. Every...
# multiplatform
s
Facing weird issue with
object
in iOS app. Everytime i'm using a method of a singleton class (tried both object as well as normal way of creating singleton), a new instance of the class is getting created, defeating the whole singleton purpose. I'm currently on Kotlin 2.0.21 and SKIE 0.9.5. Has anyone faced something similar?
y
It's outlined here .. there's a
.shared
property that should get you the singleton
s
the object class is internal, so not getting called via swift directly, still getting the issue
y
hmm, can you share a code snippet?
s
Copy code
internal object ClientHandler {

    private val clientMap = hashMapOf<String, Client>()
    private var defaultClient: Client? = null

    fun addClient(clientTag: String, client: Client, isDefault: Boolean = false) {
        clientMap[clientTag] = client
        if (isDefault) {
            defaultClient = client
        }
    }

    fun getClient(clientTag: String): Client? {
        return clientMap[clientTag]
    }

    fun getDefaultClient(): Client? {
        return defaultClient ?: clientMap.values.firstOrNull()
    }
}
@yousefa2 ^
here log inside addclient is showing different instance of handler, and getdefaultclient showing different
y
Sorry can you show me the logout and how you are determining that its a different instance as well
s
@yousefa2 like this, printed the class itself, and checking the hashcode of the instance