on the constructor, but every time I do, I get an error:
constructor with @OverrideInit doesn't override any super class constructor.
Is there an example somewhere of how to use this annotation properly? It seems no matter what I do it doesn't work.
s
svyatoslav.scherbina
06/29/2018, 5:10 AM
To “override” a constructor, your constructor should have the same parameter names and types.
Maybe you have wrong parameter names?
For example, in your code from previous thread you have
constructor(aDecoder: NSCoder)
, and
aDecoder
parameter name doesn’t match super constructor.
s
spierce7
06/29/2018, 5:16 AM
Here is what I'm doing:
Copy code
@ExportObjCClass
class ViewController @OverrideInit constructor(aDecoder: NSCoder) : UIViewController(aDecoder) {
@ObjCOutlet lateinit var label: UILabel
spierce7
06/29/2018, 5:19 AM
I still see the error when compiling
Error:(7, 1) constructor with @OverrideInit doesn't override any super class constructor.
s
svyatoslav.scherbina
06/29/2018, 5:23 AM
Your constructor should have the same parameter names and types as super constructor, which is
Copy code
constructor(coder: NSCoder)
So your constructor parameter should be
coder: NSCoder
too:
Copy code
class ViewController @OverrideInit constructor(coder: NSCoder) : UIViewController(coder) {