title: Idiomatic pattern to initialize UIViews in Swift
body: <p>In <code>Objective-C</code> I had evolved the pattern of having both an <code>awakeFromNib</code> and <code>initWithFrame:</code> method which invoked their <code>super</code>'s and then called a <code>_commonInit</code> where I put all my own code. E.g.</p>
  
  <pre><code>- (void)_commonInit {
      // Initialize stuff here
  }
  
  - (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if (self) {
          [self _commonInit];
      }
      return self;
  }
  
  - (void)awakeFromNib {
      [super awakeFromNib];
      [self _commonInit];
  }
  </code></pre>
  
  <p>So I'm trying to reuse this pattern in my UIView subclasses that I'm porting to Swift:</p>
  
  <pre><code>func _commonInit() {
      // initialize code here
  }
  
  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()
  }
  </code></pre>
  
  <p>Is this the right way to do it? I'm curious why the <code>init(coder...)</code> is <code>required</code>. Especially when all I do is call the <code>super</code> version. I seem to recall that the reason I used <code>awakeFromNib</code> in the <code>Objc</code> version was because any changes applied from nib restoration didn't happen until sometime later than <code>initFromCoder:</code>.</p>