I have a subclass UIButtonas follows:
class VectorizedButton: UIButton {
override var highlighted: Bool {
didSet {
setNeedsDisplay()
}
}
}
Everything works fine until I added this line to my root controller:
var twitterButton: TwitterButton?
TwitterButtonthe extends VectorizedButton.
Here is the error I get:
... UIView + Vectorized.swift: 42: 7: Class 'VectorizedButton' has no initializers ... UIView + Vectorized.swift: 44: 18: the stored property is "highlighted" without an initial value prevents synthesized initializers
Just set the default value:
override var highlighted: Bool = false
More severe error:
<unknown>:0: error: super.init called multiple times in initializer
<unknown>:0: error: super.init called multiple times in initializer
<unknown>:0: error: super.init called multiple times in initializer
Try to override init?
required init(coder aDecoder: NSCoder) {
highlighted = false
super.init(coder: aDecoder)
}
Even more mistakes:
error: 'self' used before super.init call
highlighted = false
^
error: 'self' used before super.init call
highlighted = false
^
Can anyone explain what is going on here?
source
share