Swift! Create a segue only if the button is pressed! Tab Bar Controller <p>Alright, so for about a few days now, I'm stuck on this problem. I have a Tab Bar Controller and I have a View Controller where users of the app either create of enter their passwords, lets call it the <strong>"Pass View"</strong>. </p> <p>The passwords are created using keychain method provided by Apple. Ideally I would want the app to first and always pop up the <strong>"Pass View"</strong> and then if users enter their password correctly then the app segues to the Tab Bar Controller. </p> <p>Now I can associate an action segue from my enter/create button to the Tab Bar Controller, but if I do that then even if the users enter their passwords incorrectly the segue will still happen.. </p> <p><strong>Link to Image 1 Showing StoryBoard: <a href="https://www.flickr.com/photos/124829893@N03/18903848374/in/dateposted-public/" rel="nofollow">StoryBoardImage</a></strong></p> <p><strong>Link to Image 2 Showing files: <a href="https://www.flickr.com/photos/124829893@N03/19338423370/in/dateposted-public/" rel="nofollow">files in my project</a></strong></p> <p>Here is my code: </p> <pre><code>import UIKit class LoginPassViewController: UIViewController { let MyKeychainWrapper = KeychainWrapper() let createLoginButtonTag = 0 let loginButtonTag = 1 @IBOutlet weak var passTextField: UITextField! @IBOutlet weak var loginButton: UIButton! override func viewDidLoad() { // 1. let hasLogin = NSUserDefaults.standardUserDefaults().boolForKey("hasLoginKey") // 2. if hasLogin { loginButton.setTitle("Login", forState: UIControlState.Normal) loginButton.tag = loginButtonTag loginButton.hidden = false } else { loginButton.setTitle("Create", forState: UIControlState.Normal) loginButton.tag = createLoginButtonTag loginButton.hidden = false } // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func enterApp(sender: AnyObject) { // 1. if passTextField.text == "" { var alert = UIAlertView() alert.title = "You must enter a password!" alert.addButtonWithTitle("Oops!") alert.show() return } // 2. passTextField.resignFirstResponder() // 3. if sender.tag == createLoginButtonTag { // 4. let hasLoginKey = NSUserDefaults.standardUserDefaults().boolForKey("hasLoginKey") // 5. MyKeychainWrapper.mySetObject(passTextField.text, forKey:kSecValueData) MyKeychainWrapper.writeToKeychain() NSUserDefaults.standardUserDefaults().setBool(true, forKey: "hasLoginKey") NSUserDefaults.standardUserDefaults().synchronize() loginButton.tag = loginButtonTag } else if sender.tag == loginButtonTag { // 6. if checkLogin(passTextField.text) { // THIS IS WHERE IF THE USER PASSWORD IS CORRECT THEN THE VIEW SHOULD SWITCH // TO THE TAB BAR CONTROLLER. } else { // 7. var alert = UIAlertView() alert.title = "Login Problem" alert.message = "Wrong username or password." alert.addButtonWithTitle("Foiled Again!") alert.show() } } } func checkLogin(password: String ) -&gt; Bool { if password == MyKeychainWrapper.myObjectForKey("v_Data") as? String { return true } else { return false } } } </code></pre>