object AnalyticsConfig {
lateinit var baseUrl: String
}
b
basher
03/14/2019, 4:02 PM
IIRC in native, all object vars are initialized as runtime init, which is different compared to JVM (lazy). To workaround this, we do something similar like this:
Copy code
import kotlin.native.concurrent.AtomicReference
private val BASE_URL = AtomicReference<String?>(null)
fun setBaseUrl(urlString: String) {
BASE_URL.value = urlString.freeze()
}
actual object AnalyticsConfig {
fun getBaseUrl() = BASE_URL.value!!
}
basher
03/14/2019, 4:03 PM
This requires making
AnalyticsConfig
an expect/actual class because you have to do native-specific concurrency stuff on the native side
g
galex
03/15/2019, 3:59 AM
Sounds like this is the way to go, thanks will try that.