I'm new to Swift, coming from web dev, so I am quite used to components. I am trying to create a form, and would like to reuse the textfield and label in other Views. I have created a new class that inherence from UIView, and want to override the init to create set new properties.
My code so far
final class TextFormField: UIView {
var labelText: String
var secureText: Bool
var keyboardType: UIKeyboardType
override init(frame: CGRect) {
super.init(frame: frame)
}
init(labelText: String, secureText: Bool, keyboardType: UIKeyboardType){
self.labelText = labelText
self.secureText = secureText
self.keyboardType = keyboardType
super.init()
}
convenience init() {
self.init()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
The error I get now is Must call a designated initializer of the superclass 'UIView'
on the second init.
How can I override the init to take 3 more parameters? Do I need to do an extension instead?
Thanks in advance