Tung97 Hl
09/07/2023, 7:48 AMcompanion object : SynchronizedObject() {
private val instanceRef: AtomicRef<DBManager?> = atomic(null)
fun create(driver: SqlDriver) = synchronized(this) {
if (instanceRef.value == null) {
val localdb = LocalDb.invoke(driver)
val instance = DBManager(localdb)
instanceRef.update { instance }
Logger.d("singleton", "$this")
}
}
fun get(): DBManager = synchronized(this) {
Logger.d("singleton", "$this")
instanceRef.value ?: throw IllegalStateException("DBManager was not created")
}
}
Problem: When I log the companion object instance in create() and get() functions, it's the same in android/JVM, but it's different in kotlin/native (ios)
DBManager.Companion@c50300a0
and
DBManager.Companion@9e050250
I have already created the instance in iOS using this code in the init block:
DBManager.companion.create(driver: CreateDBDriverKt.createDBDriver())
That makes my application always crash in iOS. Please help!