I'm trying to export some classes defined in a k/n...
# kotlin-native
k
I'm trying to export some classes defined in a k/native framework (defined using new-mpp) on iOS target to a consuming swift project. If I just define a simple class
class Foo
, this gets added to the generated
.h
and seems to work fine. It seems like if I try to subclass an objective c class, such as
class MyViewController : UIViewController
, the symbol disappears from the
.h
and then swift can't see it. Is this expected behavior? Am I missing something here?
I've tried messing with exports and initializers with no luck too, e.g.:
Copy code
@ExportObjCClass
class Foo: UIViewController {
    @OverrideInit constructor(coder: NSCoder) : super(coder)
    val bar = 1
}
s
Kotlin subclasses of Objective-C classes aren’t added to framework header currently.
l
Is there a reason? Will this change, and if yes, will this be prominently mentioned in the release notes?
s
Yes. Kotlin and Objective-C have very different subclassing models, and supporting such cases would require a lot of efforts. On the other hand, this case is not considered that useful. Why do you need this feature? Could you provide some details on your case?
k
Personally, my use case isn't that compelling. I started with a k/n framework and a swift project that depended on it because that's what the IDEA Community project template for multiplatform android/iOS made. It's becoming more clear that I need to revert that and start with a pure k/n iOS project with everything written in kotlin, that clobbers the xcode project on build, as in https://github.com/JetBrains/kotlin-native/tree/master/samples/uikit.
related: it'd be useful if there were a template in Intellij that dumped out a android/ios example that used a pure kotlin project on ios. I probably would have selected it if it had existed.
1
s
This approach is quite tricky and I don’t consider it worth to be recommended by adding a new project template.