In Objective-CI developed a template containing both a method awakeFromNiband initWithFrame:one that called them superand then called _commonInitwhere I put all my own code. For instance.
- (void)_commonInit {
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self _commonInit];
}
return self;
}
- (void)awakeFromNib {
[super awakeFromNib];
[self _commonInit];
}
So, I'm trying to reuse this template in my subclasses of UIView, which I port to Swift:
func _commonInit() {
}
override init(frame:CGRect) {
super.init(frame:frame)
self._commonInit()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func awakeFromNib() {
super.awakeFromNib()
self._commonInit()
}
Is this the right thing to do? I'm curious why init(coder...) required. Especially when all I do is call the version super. I, it seems, remember that the reason I used awakeFromNibin the version Objcwas that any changes applied in restoring nib did not happen earlier than initFromCoder:.