I was having trouble accessing the companion object instance from Swift code. We could access it, but had to create an instance of the companion object to do so, i.e.
<Kotlin Class>.Companion().<companion function>()
. Did we overlook something, or is this a known limitation?
k
kpgalligan
07/15/2019, 8:34 PM
You have to do the same with regular top level objects. I assume under the hood the
Companion()
call returns a single instance if called multiple times, but will defer to others
✔️ 1
s
spierce7
07/15/2019, 8:35 PM
So
Companion()
is exposed as a function, not a class?
s
Sam
07/15/2019, 8:36 PM
No. It is constructing an instance but the way ObjC memory allocation/initialization works, it is effectively a constructor that always returns the same instance.