I have a problem with `val` in `companion object` ...
# kotlin-native
r
I have a problem with
val
in
companion object
having incorrect value on iOS, anyone saw anything about that? For example I have this in a subclass of
UICollectionViewCell
(hence the object superclass):
Copy code
companion object : UICollectionViewCellMeta() {
        const val HEIGHT = 100.0
    }
But when I print the value of
HEIGHT
anywhere it has a nonsense value, maybe returning a pointer or reading random memory, it returns something like 6e-310. It also does not return the same value every time its read from different instances of the subclass of
UICollectionViewCell
. Wtf? Note: Removing
const
doesn’t change anything. No problem if the
val
is global, local to the class or a getter (
val HEIGHT: Double get() = 100.0
)
k
my guess is that your companion object has not been instantiated
r
🤨
k
subclasses of NSObject aren't accessible from native code...
r
@Kris Wong what does that mean
k
they are marked as inaccessible in the interface header
r
Maybe, I still don’t see any link to the issue here
I don’t understand why companion objects of subclasses of NSObject aren’t instantiated while other companion objects are. I also don’t know if I can force their instantiation
k
you are saying this only occurs for classes that subclass NSObject
those classes are inaccessible from the native side
Copy code
__attribute__((unavailable("Kotlin subclass of Objective-C class can't be imported")))
__attribute__((swift_name("FeatureViewController")))
@interface FeatureModuleFeatureViewController : NSObject
@end;
r
What native side? Everything is native
Or maybe, nothing is native. I don’t know what you mean, I’m not using any Objective-C or Swift
k
you said "having incorrect value on iOS", so I assumed you were accessing it from an iOS app
r
I do, but I only have Kotlin code