Skip to content
This repository was archived by the owner on Aug 10, 2021. It is now read-only.
This repository was archived by the owner on Aug 10, 2021. It is now read-only.

Error accessing companion object members from Swift #2571

@philmitchell

Description

@philmitchell

From Swift, I try to access the companion object like this:

let p = Ping.Companion()
let d = p.NO_DISTANCE

The compiler error (Swift 4.2):

'NO_DISTANCE' has been renamed to 'no_DISTANCE'
'NO_DISTANCE' was obsoleted in Swift 3

Sure enough, I am able to access it like this:

let d = p.no_DISTANCE

Here is the Kotlin code:

data class Ping(
    val id: String,
    val distance: Double,
    val rssi: Int
) {
    companion object {
        const val NO_DISTANCE: Double = -1.0
        const val NO_RSSI: Int = 10000
    }
}

Here is the relevant section from the library header file:

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Ping.Companion")))
@interface MyLibPingCompanion : KotlinBase
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
+ (instancetype)companion __attribute__((swift_name("init()")));
@property (readonly) double NO_DISTANCE;
@property (readonly) int32_t NO_RSSI;
@end;

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions