How to programmatically create a button to appear in separate view controller swift
<p>I created a function in <code>ViewController</code> one that creates a <code>UIButton</code>. </p>

<p>When I call the function in the same <code>ViewController</code>, in <code>ViewDidLoad</code>, it works fine.  But when I try calling the function with a button I created in a popover, I keep getting this </p>

<blockquote>
  <p>Error "Thread1:EXC_BREAKPOINT(code=1, subcode=0x1002ce588)".</p>
</blockquote>

<p>I realize this is a common Error but I can not seem to find a way around it. </p>

<p>Here is what I have. </p>

<pre><code>class func addButtonToMainController()
{
    var button1: UIButton!
    button1 = UIButton(type: .System)
    button1.setTitle("placeholder", forState: UIControlState.Normal)
    button1.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
    button1.center = CGPoint(x: 0, y: 0)
    button1.titleLabel?.font = UIFont.systemFontOfSize(20)
    button1.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
    button1.backgroundColor = UIColor.blueColor()
    button1.addTarget(MainViewController(), action: Selector("animateButtonPressed:"), forControlEvents: UIControlEvents.TouchUpInside)
    MainViewController().view.addSubview(button1)
}
func animateButtonPressed(sender: AnyObject){
    print("animate")
}
</code></pre>

<p>here is where I call the function, from the popover viewcontroller.</p>

<pre><code>@IBAction func buttonPressed(sender: AnyObject) {
    MainViewController.addButtonToMainController()
}
</code></pre>

<p>The point here is to create a working button on the main view controller while in the popover. any help would be greatly appreciated. thank you.</p>