Thread
#multiplatform
    Luoqiaoyou

    Luoqiaoyou

    2 years ago
    i got error "Unable to call non-designated initializer as super constructor", when i try to inherit WKWebView in ios.
    Artyom Degtyarev [JB]

    Artyom Degtyarev [JB]

    2 years ago
    Seems like you already found an issue with explanations(https://github.com/JetBrains/kotlin-native/issues/2010). One can use only designated initializers when inheriting, for this class they are
    initWithFrame:configuration
    and
    initWithCoder
    . I’ve made this snippet to prove, that it should work correctly:
    import kotlinx.cinterop.*
    import platform.WebKit.WKWebView
    import platform.WebKit.WKWebViewConfiguration
    import platform.Foundation.NSZeroRect
    
    class myWebView : WKWebView(frame = NSZeroRect.readValue(), configuration = WKWebViewConfiguration())
    Luoqiaoyou

    Luoqiaoyou

    2 years ago
    wow,it works. but how can i know which constructor is designated initializers?
    Artyom Degtyarev [JB]

    Artyom Degtyarev [JB]

    2 years ago
    That’s where the problem comes, in fact. One can check the frameworks headers contents manually, for example in the WKWebView.h there are such lines:
    - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
    - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
    the
    NS_DESIGNATED_INITIALIZER
    macro is what you need.