Just sharing a learning moment here that's probabl...
# multiplatform
b
Just sharing a learning moment here that's probably well-covered by documentation but was still a surprise. I was running into a
IncorrectDereferenceException
from swift code that depends on a shared kotlin module. The error specified
ExitEntity$impl
as the problematic class which is a
data class
code generated by sqldelight. I thought IncorrectDereferenceException is just thrown when some top-level variable is accessed off the main thread and isn't annotated with @ThreadLocal or @SharedImmutable. I was able to address by making the query within the kotlin module and freezing the object before it is used on the swift-side. I started off debugging by writing an
iosTest
within my shared kotlin module that retrieves an ExitEntity from the database on one thread and then accesses a field of the object on a different thread. The test passes without an exception being thrown. My takeaway is that kotlin objects referenced in swift need to be frozen if passed between threads, even though the same object can be passed between threads without issue if solely in kotlin code.
👍 1
k
it's frozen automatically when you do it within kotlin code
👍 1