I am trying to implement the follow function in my application. Essentially, when the user clicks the follow button, we run runTransactionBlock to update the integer values ββthat we store in the Firebase database for the user and the account that they follow. The problem is that I can update the counter for the user (say John in the example below), but I cannot update the counter for the user I visit (say, olivia in the example below).
Currently, Firebase nodes look like these:
user_profiles{ UID1:{ name: john following: 1
I refer to the following, however, I'm still having problems getting this to work. If someone could overlook and point me in the right direction, that would be greatly appreciated.
https://www.firebase.com/docs/ios/guide/saving-data.html
Firebase Database Help - Swift
Upvote / Downvote system in Swift through Firebase
var guestUIDToPass = String() var loggedInUser = AnyObject() @IBAction func didTapFollow(sender: AnyObject) { following() } func following() { self.loggedInUser = FIRAuth.auth()?.currentUser //updating count for user, works perfectly self.databaseRef.child("user_profiles").child(self.loggedInUser.uid).child("following").runTransactionBlock({ (currentData:FIRMutableData!) in var value = currentData.value as? Int if (value == nil) { value = 0 } currentData.value = value! + 1 return FIRTransactionResult.successWithValue(currentData) }) //updating count for person user is following, doesn't update firebase self.databaseRef.child("user_profiles").child("\(self.guestUIDToPass)").child("followers").runTransactionBlock({ (currentData:FIRMutableData!) in var value = currentData.value as? Int if (value == nil) { value = 0 } currentData.value = value! + 1 return FIRTransactionResult.successWithValue(currentData) }) }
ios swift firebase firebase-database
gk103
source share