title: How to transfer data between view controller using segues
body: <p>I'm trying to pass data using a <code>prepare(for segue:)</code> function but it's showing nil in the second VC. Am I doing anything wrong?</p>
  
  <pre><code>class ViewController: UIViewController {
  
      var first : [String] = []
  
      @IBOutlet weak var passField: UITextField!
      @IBOutlet weak var userID: UITextField!
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
      @IBAction func login(_ sender: Any) {
          let user : String = self.userID.text!
          let password : String = self.passField.text!
  
          if user != "" &amp;&amp; password != "" {
              let postString = ["username":user, “password”: password]
              var request = URLRequest(url:URL(string:"http://mydomainhere.com/api/login")!)
              request.httpMethod = "POST"
              request.httpBody = try! JSONSerialization.data(withJSONObject: postString, options:.prettyPrinted)
              let task = URLSession.shared.dataTask(with: request) { (data: Data?, response: URLResponse?, error: Error?) in
                  if error != nil {
                      print("error=\(error)")
                      return
                  }
  
                  do {
                      if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] {
                          let firstName = json["first_name"] as? String
                          let lastName = json["last_name"] as? String
                          self.first.append(firstName!) //putting into Array
                          self.performSegue(withIdentifier: "loginSegue", sender: self)
                      }
                  } catch {
                      print(error)
                  }
              }
          }
      }
  
      // data transfer to another controller
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          if segue.identifier == "loginSegue" {
              let secondController = segue.destination as? SecondVC
              secondController?.name = first //passing to next VC   //* here having the issue its not passing the data to next VC
              print(first)    // here first is printing perfectly
          }
      } 
  }
  
  
  // second View Controller
  class SecondVC: UIViewController {
  
      var menu_vc : MenuViewController!
      var name : [String]?    // passing to this Array
  
      override func viewDidLoad() {
          super.viewDidLoad()
          print(name)    // here printing nil 
      }
  }
  </code></pre>