title: Appending Elements to Array
body: <p>I try to append elements to an array to later use that data and create a TableView as a Leaderboard.
  I've already read through every post I could find but none of them worked out for me. </p>
  
  <p>I have a Firebase Database where I get the UserData from. Here is the Node:</p>
  
  <h2><a href="https://i.stack.imgur.com/k68Xj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k68Xj.png" alt="Firebase Node for a Single user"></a></h2>
  
  <p>Here you can see my class that handles this ViewController:</p>
  
  <pre><code>import UIKit
  import FirebaseDatabase
  import FirebaseAuth
  
  class LeaderboardViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
      @IBOutlet weak var tableView: UITableView!
      var users:[User] = []
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.tableView.reloadData()
      }
  
      override func viewWillAppear(_ animated: Bool) {
          load()
      }
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return users.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "leaderCell") as! LeaderboardTableViewCell
          cell.placing.text = "\(indexPath.item+1)"
          cell.points.text = "\(indexPath.item + 20)"
          cell.name.text = "TestUser"
          return cell
      }
  
     func load(){
          let ref = Database.database().reference(withPath: "users")
          ref.observeSingleEvent(of: .value) { (snapshot) in
              let value = snapshot.value as? NSDictionary
  
              for key in value!.allKeys{
                  ref.child("\(key)").observeSingleEvent(of: .value) { (snapshot) in
                      let userinfo = snapshot.value as? NSDictionary
  
                      let username = userinfo?.value(forKey: "username") as! String
                      let year = userinfo?.value(forKey: "year") as! String
                      let points = userinfo?.value(forKey: "points") as! Int
  
                      self.users.append(User(username: username, useryear: year, userpoints: points))
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I try to retrieve the data when my ViewController "will load" so that when the view did appear I can reload the TableView Data. 
  The Problem is, the data that I get won't get saved into the array. </p>
  
  <p>I already tried initialising the array with 6+ elements but that didn't change anything. 
  I also read that it could have something to do with the fact that I use a for-each loop but I couldn't figure out how to fix it.</p>