Kotlin-native: Combine classes with companion objects in Objective C frameworks?

Created on 30 Apr 2018  路  3Comments  路  Source: JetBrains/kotlin-native

I'm just testing out using Kotlin Native to create a cross-platform library, and so far it looks fantastic! One wrinkle, though: when I make an Objective C framework (for use on iOS) it exports MyClass just fine, but also outputs MyClassCompanionObject, with static functions attached.

I understand why that's happening, and in many ways it's the more correct interpretation of the Kotlin code, but it doesn't match any pattern used in Objective C or Swift. Is there any way to combine these two classes to provide static functions on the original class?

enhancement need info

Most helpful comment

I would suggest an opt-in mechanism, probably something like @JvmStatic but for Objective-C. object (free or companion) members annotated with e.g. @ObjCStatic would cause the compiler to emit a static bridge (on the enclosing class in the case of companion objects, otherwise on the actual object type).

All 3 comments

What criteria would you suggest for putting methods out of companion to statics of the Objective-C class?

I would suggest an opt-in mechanism, probably something like @JvmStatic but for Objective-C. object (free or companion) members annotated with e.g. @ObjCStatic would cause the compiler to emit a static bridge (on the enclosing class in the case of companion objects, otherwise on the actual object type).

According migration to YouTrack, closing this issue in favour of https://youtrack.jetbrains.com/issue/KT-44862. Please continue any discussions there.

Was this page helpful?
0 / 5 - 0 ratings