追随者计数器不更新Firebase中的节点

我一直在试图在我的应用程序上实现“跟随”function。 实际上,当用户点击“关注”button时,我们运行runTransactionBlock来更新我们存储在Firebase数据库中的用户和他们所关注的帐户的整数值。 问题是,我能够更新计数器的用户(说约翰在下面的例子中),但我不能更新我所关注的用户的计数器(奥利维亚在下面的例子中说)。

目前,Firebase节点如下所示:

 user_profiles{ UID1:{ name: john following: 1 //code will update for my account followers: 0 }, UID2:{ name: olivia following: 0 followers: 0 //code will not update count for person i am trying to follow 

我已经参考了以下,但我仍然面临着这个工作的问题。 如果任何人都可以请扫一眼,指向正确的方向,这将不胜感激。

https://www.firebase.com/docs/ios/guide/saving-data.html

Firebase数据库帮助 – Swift

Upvote / Downvote系统内的Swift通过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) }) } 

尝试:-

 let prntRef = FIRDatabase.database().reference().child("user_profiles").child(whomIFollowedUID).child("following") prntRef.runTransactionBlock({ (following) -> FIRTransactionResult in if let followNum = following.value as? Int{ following.value = followNum + 1 return FIRTransactionResult.successWithValue(following) }else{ return FIRTransactionResult.successWithValue(following) } }, andCompletionBlock: {(error,completion,snap) in print(error?.localizedDescription) print(completion) print(snap) if !completion { print("The value wasn't able to Update") }else{ //Updated } })