title: Append a name to array after a button is clicked and then send it to another view controller
body: <p>I'm trying to make a favourite button in my app where if the favourite image is tapped then it will append the name of the place to an array and then pass that array over to a table view inside a UIViewController. I have got it to pass an array with predetermined values inside but when I try to append names into the array and then pass it, the array in the next view controller comes out as empty.</p>
  <p>This is in my first view controller:</p>
  <pre><code>    var fave: [String] = []
  
      @IBAction func faveTapped(_ sender: UIButton) {
          fave.append(name)
          let defaults = UserDefaults.standard
          defaults.set(fave, forKey: &quot;faves&quot;)
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  </code></pre>
  <p>I have this in my second view controller with the table view:</p>
  <pre><code>class nextViewController: UIViewController {
      
      var newArray: [String] = []
  
      @IBOutlet var tableView: UITableView!
      
      override func viewDidLoad() {
          super.viewDidLoad()
          
          if let oldArray: [String] = UserDefaults.standard.object(forKey: &quot;faves&quot;) as? [String] {
              newArray = oldArray
          }
          
          print(newArray)
      }
  }
  
  extension FavouritesViewController: UITableViewDataSource {
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return newArray.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let rowcell = tableView.dequeueReusableCell(withIdentifier: &quot;rowcell&quot;, for: indexPath)
  
          rowcell.textLabel?.text = newArray[indexPath.row]
  
          return rowcell
      }
  }
  </code></pre>