title: Swift/Firebase change value from tableview
body: <p>Basically I am experiencing some difficulties trying to change the value from Firebase in a tableview. I am currently trying to make a Facebook-post-like feature, allowing people to like your post. However, I am not quite sure how I would proceed with this. I want to give the user the ability to like each post, and then save the previous likes + the like that was given, and update it in firebase. As of right now, I only have the code to display each post, and also the @IBAction from the button(Like button). </p>
  
  <p>I am not sure how I would manage to access each specific post through only the table view, using indexPath.row(?). Here is the code I have so far:</p>
  
  <p>Post edit:</p>
  
  <p>So basically I have a tableview, containing a table view cell that displays the amount of likes each post has. To do this, I have this code in my viewDidLoad(), to just fetch the data from Firebase:</p>
  
  <pre><code>ref.childByAppendingPath("posts").queryOrderedByChild("timeRegistered").observeEventType(FEventType.ChildAdded) { (snapshot:FDataSnapshot!) in
  
          var dict = [String:String]()
          dict["keys"] = snapshot.key as? String
          dict["votes"] = snapshot.value["likes"] as? String
          self.posts.append(dict)
  
          self.tableView.reloadData()
  
  
      }
  </code></pre>
  
  <p>Just to mention, this code works, by using this code in the cellForRowAtIndexPath: <code>cell.textLabel!.text = String(posts[indexPath.row]["names"]!)</code></p>
  
  <p>However, I thought that the code that I used in viewDidLoad (.ChildAdded function) would work with ChildChanged as well, so this is what I came up with:</p>
  
  <pre><code>ref.childByAppendingPath("posts").queryOrderedByChild("timeRegistered").observeEventType(FEventType.ChildChanged) { (snapshot:FDataSnapshot!) in
  
          var dict = [String:String]()
          dict["keys"] = snapshot.key as? String
          dict["votes"] = snapshot.value["votes"] as? String
          self.posts.append(dict)
  
          self.tableView.reloadData()
  
  
      }
  </code></pre>
  
  <p>Unfortunately, it looks like the tableview just displays the new value (the value changed from an IBAction, I'll provide this code as well.) - while the old value just stays there. This is the code for changing value:</p>
  
  <pre><code>var key = posts[1]["keys"]
      ref.childByAppendingPath("posts").childByAppendingPath(key!).updateChildValues(["name":"Test name"])
      tableView.reloadData()
  </code></pre>
  
  <p>Still trying to figure out a better way of changing the exact value, through index - but that is not the case now (therefore posts[1]["keys"]). Do you seem to understand what the problem is?</p>
  
  <p>To sum up: I want to click a button inside a table view cell, and adding a like to the specific post, and updating the total count in real time.</p>