title: Variable unexpectedly resetting to 0 when View Controller Switched
body: <p>I had a variable called &quot;results&quot; in a ViewController called DetailViewController which is given a value, and is printed correctly in FirstViewController:</p>
  <pre><code>extension FirstViewController: UITableViewDataSource{
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return posts.count
      }
       func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: &quot;PostCell&quot;, for: indexPath) as! PostTableViewCell
          
          cell.typeLabel.text = &quot;Name: \(posts[indexPath.row].typeOfFood)&quot;
          cell.titleLabel.text = &quot;Title: \(posts[indexPath.row].title)&quot;
          cell.locationLabel.text = &quot;Location: \(posts[indexPath.row].location)&quot;
          cell.nameLabel.text = &quot;Name: \(posts[indexPath.row].name)&quot;
          return cell
          
      }
      
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  //        print(&quot;Select Row \(indexPath.row)&quot;)
          var result = indexPath.row
          tableView.deselectRow(at: indexPath, animated: true)
  //        self.performSegue(withIdentifier: &quot;showDetail&quot;, sender: nil)
          let mainStoryBoard = UIStoryboard(name: &quot;Main&quot;, bundle: Bundle.main)
          guard let detailViewController = mainStoryBoard.instantiateViewController(withIdentifier: &quot;DetailViewController&quot;) as? DetailViewController else{
              print(&quot;couldnt find vc&quot;)
              return
          }
          let detailVC = DetailViewController()
          detailVC.result = indexPath.row
          print(detailVC.result)
          self.present(detailViewController, animated: true, completion: nil)
  
  
  
      }
  }
  </code></pre>
  <p>But then when my app switches to another ViewController called DetailViewController, The variable result is always printed and stored as 0. DetailViewController:</p>
  <pre><code>import UIKit
  import Firebase
  import FirebaseDatabase
  class DetailViewController: UIViewController {
  
      @IBOutlet weak var backButton: UIBarButtonItem!
      @IBOutlet weak var nameOfUserLabel: UILabel!
      @IBOutlet weak var typeOfFoodNeededLabel: UILabel!
      @IBOutlet weak var amountOfFoodNeededLabel: UILabel!
      @IBOutlet weak var reasonNeededLabel: UILabel!
      @IBOutlet weak var descriptionLabel: UILabel!
      @IBOutlet weak var locationLabel: UILabel!
      @IBOutlet weak var imageView: UIImageView!
      @IBOutlet weak var messageButton: UIButton!
       var posts = [Posts]()
      var rowNumber = String()
      var result = Int()
      override func viewDidLoad() {
          super.viewDidLoad()
          var rowNumber = Int()
          loadPosts()
  print(result)
  //        nameOfUserLabel.text = posts[result].name
  
      }
      
      func loadPosts() {
          Database.database().reference().child(&quot;Posts&quot;).observe(.childAdded){(snapshot: DataSnapshot) in
              if let dict = snapshot.value as? [String: Any]{
                  
                  let titleText = dict[&quot;Title&quot;] as! String
                  let typeofFoodText = dict[&quot;Type of Food&quot;] as! String
                  let descriptionText = dict[&quot;Description&quot;] as! String
                  let amountNeededText = dict[&quot;Number of Items Needed&quot;] as! String
                  let locationText = dict[&quot;Location&quot;] as! String
                  let nameText = dict[&quot;Name of User&quot;] as! String
                  let reasonNeeded = dict[&quot;Reason for Donation&quot;] as! String
                  
                  
                  let post = Posts(titleText: titleText, typeOfFoodText: typeofFoodText, descriptionText: descriptionText, amountNeededText: amountNeededText, locationText: locationText, nameText: nameText, reasonNeededText: reasonNeeded)
                   
                  self.posts.append(post)
                  print(self.posts)
  
                  self.nameOfUserLabel.text = self.posts[self.result].name
                  self.descriptionLabel.text = self.posts[self.result].description
                  self.typeOfFoodNeededLabel.text = self.posts[self.result].typeOfFood
                  self.amountOfFoodNeededLabel.text = self.posts[self.result].amountNeeded
                  self.reasonNeededLabel.text = self.posts[self.result].reasonNeeded
                  self.locationLabel.text = self.posts[self.result].location
  
                  
                  
              }
  
          }
  
  
      }
      ```
  </code></pre>
  <p>How can I fix this? I mainly want the value it is given in FirstViewController to carry over to the DetailViewController, but it keeps resetting back to 0.</p>