A designated initializer of a subclass needs to call the designated initializer of Superclass. A convenience initializer can only call another convenience initializer or a designated initializer of that class.
init() is a convenience initializer for UIView, if you subclass UIView you should call its designated initializer which is init(frame: frame)
override init() {
super.init(frame: frame)
// Some init logic ...
}
EDIT: Apparently in Beta 3, UIView doesn't have convenience initializer called as init, so you need to remove the override keyword too, now this is a designated initializer so you need to call superclass's designated initializer
init() {
super.init(frame: frame)
// Some init logic ...
}
EDIT: Although this works but I think a better way to write this would be:
convenience init() {
self.init(frame:CGRectZero)
}
Source:Swift documentation
Rule 1 A designated initializer must call a designated initializer
from its immediate superclass.
Rule 2 A convenience initializer must call another initializer from
the same class.
Rule 3 A convenience initializer must ultimately call a designated
initializer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…