title: Custom UIButton throw multiple design errors
body: <p>I'm dealing with an XCode error that I don't understand, I've been looking for solutions for days now, and Pods update, XCode restart or anything else doesn't seem to throw the problem away ... </p>
  
  <p>I have a custom class which extends from UIButton : </p>
  
  <pre><code>import Foundation
  import UIKit
  
  //@IBDesignable  &lt;-- COMMENTED BUT SAME ERRORS ... 
  class CustomCardButton: UIButton {
  
      var nibName = "CustomCardButton"
  
      @IBOutlet weak var btnImageView: UIImageView!
      @IBOutlet weak var btnLabel: UILabel!
  
      @IBInspectable var image: UIImage? {
          get {
              return btnImageView.image
          } set(image) {
              btnImageView.image = image
          }
      }
  
      @IBInspectable var label: String? {
          get {
              return btnLabel.text
          } set(label) {
              btnLabel.text = label
          }
      }
  
      override init(frame: CGRect) {
          super.init(frame: frame)
          setup()
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          setup()
      }
  
      func setup() {
          let view = loadViewFromNib()
          view.frame = self.bounds
          view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
          btnImageView.layer.cornerRadius = 60/2
          btnImageView.layer.borderColor = UIColor(red: 5/255,
                                                   green: 66/255, blue: 38/255, alpha: 1).CGColor
          btnImageView.layer.borderWidth = 2
          btnLabel.font = UIFont.boldSystemFontOfSize(14.0)
          btnImageView.userInteractionEnabled = true
          btnLabel.userInteractionEnabled = true
          view.userInteractionEnabled = true
          addSubview(view)
      }
  
      func loadViewFromNib() -&gt; UIButton {
          let bundle = NSBundle(forClass: self.dynamicType)
          let nib = UINib(nibName: nibName, bundle: bundle)
          let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIButton
          return view
      }   
  }
  </code></pre>
  
  <p>It's a well copy-pasted code from SO : <a href="https://stackoverflow.com/questions/35317796/swift-custom-uibutton-does-not-work-when-click">Swift, Custom UIButton does not work when click</a></p>
  
  <p>And my xib file looks like this : </p>
  
  <p><a href="https://i.stack.imgur.com/Szaff.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Szaff.png" alt="enter image description here"></a></p>
  
  <p>I kept it simple for now, yesterday I tried it with a more complicated (Yeah 2 labels and an imageview Woooh, complicated for xcode ... ) and I had the same error .. </p>
  
  <p>The errors are : </p>
  
  <p>Pre-compilation : </p>
  
  <p><a href="https://i.stack.imgur.com/Qi7k3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qi7k3.png" alt="enter image description here"></a></p>
  
  <p>After app launch it crashes and I have this : </p>
  
  <p>30 <code>let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIButton</code><br>
  <strong>Thread 1 : EXC_BAD ACCESS (code = 2, address = 0x16fc5bfd0)</strong></p>
  
  <p>31 <code>let view = loadViewFromNib()</code><br>
  <strong>Thread 1 : EXC_BAD ACCESS (code = 2, address = 0x16fc5bfd0)</strong></p>
  
  <p>32 <code>setup()</code><br>
  <strong>Thread 1 : EXC_BAD ACCESS (code = 2, address = 0x16fc5bfd0)</strong></p>
  
  <p>And I got those errors from 31 to 2840 ...</p>
  
  <p>I saw it was an XCode bug, and we cannot do anything about that, but I really need a Custom button with 2 labels and an ImageVIew ...</p>