My module is for ios/android. I’ve got an error `I...
# multiplatform
p
My module is for ios/android. I’ve got an error
IncorrectDereferenceException: illegal attempt to access non-shared ...
the object is created in
commonMain
part of the code, on a background thread. if I switch to main thread on kotlin part it works fine. but if I switch on iOS one, this crash occurs on access to the object. looks like
freeze()
is only available from ios part. Or am I missing some imports? How can I freeze an object in common code?
n
Yes
freeze()
is on native currently, you can write your own
expect
in the common, which actually freezes only on the native part, does nothing on jvm
👍 1
Also if you are using ktor, and don’t mind depending on them, you can use their
makeShared()
, which is essentially the same as ☝️
👍 1
a
This is not supported out of the box, but there are several approaches available. For example, there was a related question some time ago: https://kotlinlang.slack.com/archives/C3SGXARS6/p1598107685016400
👍 1