Is it possible to write UI Components with UI Kit ...
# kotlin-native
s
Is it possible to write UI Components with UI Kit and export them as a framework? Currently getting the following error.
Kotlin subclass of Objective C class can't be imported
For this class
Copy code
@ExportObjCClass
public class MyView: UIView {
    private val helloWorldLabel = UILabel()
    @OverrideInit
    constructor(coder: NSCoder) : super(coder)
    @OverrideInit
    public constructor(frame: CValue<CGRect>) : super(frame) {
    
        helloWorldLabel.apply {
            text = "Hello World"
            translatesAutoresizingMaskIntoConstraints = false
        }
        NSLayoutConstraint.activateConstraints(
            listOf(
                helloWorldLabel.centerXAnchor.constraintEqualToAnchor(this.centerXAnchor),
                helloWorldLabel.centerYAnchor.constraintEqualToAnchor(this.centerYAnchor)
            )
        )
        this.addSubview(this.helloWorldLabel)
    }
    @ObjCAction
    fun layoutSubviews() {
    }
}
k
yes and no. as you can see, types that inherit from NSObject are restricted on the import side of things.
s
Ok, so in this sample they seem to have it working. Im just a bit confused as to why it wouldnt work here. https://github.com/JetBrains/kotlin-native/blob/master/samples/uikit/src/iosMain/kotlin/ViewController.kt
k
there's a rather unsavory workaround that essentially amounts to you writing a C-style API that works with your MyView class, but uses the UIView type
s
Hmmm... Ok, we are looking to build our components in multiplatform on iOS.... This seems to be launching the app...