Switching view controllers in swift
<p>I've got 2 view controllers. The main one mainMenuViewController, and the secondary one ViewController.</p>

<p>The secondary view controller has an alert that is sometimes displayed, and when the user selects "Cancel", I want the mainMenuViewController to be displayed.</p>

<p>How can I achieve this with code?</p>

<p>So far I've got the following:</p>

<pre><code>       let refreshAlert = UIAlertController(title: "You Win!", message: "Do you want to play again?", preferredStyle: UIAlertControllerStyle.Alert)

        refreshAlert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { (action: UIAlertAction!) in
            self.restart()
        }))

        refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action: UIAlertAction!) in
            print("Handle Cancel Logic here")
        }))

        presentViewController(refreshAlert, animated: true, completion: nil)
</code></pre>

<p>When the user clicks Cancel, I've temporarily printed the line print("Handle Cancel Logic here"), but I need the mainMenuViewController to become active.</p>

<p>I've tried creating a function to do this, but it won't work, can you suggest why?</p>

<pre><code>@IBAction func quit(sender: UIBarButtonItem) {
    let vc = mainMenuViewController()
    self.presentViewController(vc, animated: true, completion: nil)
}
</code></pre>

<p>Any help appreciated!</p>