i got error "Unable to call non-designated initi...
# multiplatform
l
i got error "Unable to call non-designated initializer as super constructor", when i try to inherit WKWebView in ios.
a
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:
Copy code
import kotlinx.cinterop.*
import platform.WebKit.WKWebView
import platform.WebKit.WKWebViewConfiguration
import platform.Foundation.NSZeroRect

class myWebView : WKWebView(frame = NSZeroRect.readValue(), configuration = WKWebViewConfiguration())
l
wow,it works. but how can i know which constructor is designated initializers?
a
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:
Copy code
- (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.