How can I go back to the initial view controller in Swift?

SWIFT: You should use an unwind segue.

  1. First of all, put the following line in your FirstViewController:

    @IBAction func prepareForUnwind(segue: UIStoryboardSegue) {
    
    }
    

    The function actually doesn’t have any code inside it.


  1. Now, go to your storyboard and create an unwind segue for LogoutViewController by control-dragging from the yellow button to the Exit button. Like this:

control-dragging in action

  1. Select the unwind segue created for FirstViewController.

  2. Change the segue identifier:

selected segue


changing the identifier of the segue

  1. Go to the code of LogoutViewController and just call the unwind segue normally:

    self.performSegueWithIdentifier("unwindToViewController1", sender: self)
    

    Swift 4

    self.performSegue(withIdentifier: "unwindToViewController1", sender: self)
    

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)