title: UIButton throwing Thread1: EXC_BAD_ACCESS (code=1, address 0x...) in Swift
body: <p>I am creating a UIButton in another file opposed to the main ViewController. I created this button</p>
  
  <pre><code>var newNoteButton = UIButton(frame: CGRectMake(5, 18, 152.5, 37))
  newNoteButton.backgroundColor = UIColor.grayColor()
  newNoteButton.addTarget(self, action: ("newNoteButtonAction:"), forControlEvents: UIControlEvents.TouchUpInside)
  newNoteButton.setTitle("New Note", forState: UIControlState.Normal)
  newNoteButton.userInteractionEnabled = true
  self.view.addSubview(newNoteButton)
  </code></pre>
  
  <p>with action</p>
  
  <pre><code>func newNoteButtonAction (sender: UIButton!){
      println("New Note")
  }
  </code></pre>
  
  <p>It is throwing the above error even though, if i copy and paste the same code into my ViewController, it doesn't flag me at all. Why is it doing this? It is meant to just print out the string "New Note" but something causes Thread 1 to queue.</p>
  
  <p>Edit:
  After a bit of reading, I have been able to reduce the amount of code to just this:</p>
  
  <pre><code>    var newNoteButton = UIButton(frame: CGRectMake(5, 18, 152.5, 37))
      newNoteButton.backgroundColor = UIColor.grayColor()
      newNoteButton.addTarget(self, action: ("newNoteButtonAction:"), forControlEvents: UIControlEvents.TouchUpInside)
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>func newNoteButtonAction (sender: UIButton!){
      println("New Note")
  }
  </code></pre>
  
  <p>I tried removing the action and the problem was still there. This exists within my textView class in a separate file. In my AppDelegate file, the Root View Controller is ViewController. If I move the button to ViewController, the issue does not present itself. The only code in my ViewController is this</p>
  
  <pre><code>import Foundation
  import UIKit
  
  class ViewController: UIViewController, UITextViewDelegate, UIScrollViewDelegate {
  
  init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
      super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  }
  //Global Variables
  var scrollView = UIScrollView()
  
  override func viewDidLoad(){
      super.viewDidLoad()
  
      //Add textView
      //let textViewRef = textView() Removed to test
      //self.view.addSubview(textViewRef.view)
  
      //Button Code
      var newNoteButton = UIButton(frame: CGRectMake(5, 18, 152.5, 37))
      newNoteButton.backgroundColor = UIColor.grayColor()
      newNoteButton.addTarget(self, action: ("newNoteButtonAction:"), forControlEvents: UIControlEvents.TouchUpInside)
      self.view.addSubview(newNoteButton)
  
  }
  
  func newNoteButtonAction (sender: UIButton!){
      println("New Note")
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have tried messing about with conditionals and the semicolon in the action but that doesn't seem to affect it or help in any way. If you need any more information, please feel free to ask.</p>
  
  <p>Edit 2</p>
  
  <p>My other View Controller looks like this:</p>
  
  <pre><code>import Foundation
  import UIKit
  class textView: UIViewController {
  //Globals
  var newNoteButton = UIButton()
  
  override func viewDidLoad() 
  
      newNoteButton = UIButton(frame: CGRectMake(5, 18, 152.5, 37))
      newNoteButton.backgroundColor = UIColor.grayColor()
      newNoteButton.addTarget(self, action: ("newNoteButtonAction:"), forControlEvents: UIControlEvents.TouchUpInside)
      self.view.addSubview(newNoteButton)
  
  }
  
  func newNoteButtonAction (sender: UIButton!){
      println("New Note")
  }
  }
  </code></pre>
  
  <p>Edit 3: I just noticed that this information might be a bit relevant. The error is on the <code>class AppDelegate</code> line in my delegate file.</p>