2017-04-03 40 views
2

我希望當用戶已經按下downvote時,下次按下投票按鈕時,它們將從downvote字典中移除。爲什麼要移除Firebase中的數據removeValue()不起作用?

enter image description here

Firebase.getDownvote(selectedPostTimeStamp: postItem.timeStamp) { (error, downvoteFinalDictionary) in 
     let keyExists = downvoteFinalDictionary?[Current.user.userID!] != nil 

     // if the current user exists in the downvote dictionary 
     if keyExists { 
      print("Current UID exist") 
      // remove the current user from the downvote dictionary 
      self.databaseRef.child("channels").child(Current.user.channel).child("posts").child("post").child(Current.user.userID!).removeValue() 

     } else { 
      // uid doesn't exist 
     } 

我也試過這個:(

self.databaseRef.child("channels").child(Current.user.channel).child("posts").child("post").child(Current.user.userID!).removeValue(completionBlock: { (error, databaseReference) in 
       print("\n\n\n DATA IS SUPPOSED TO BE GONE!!!!!") 
      }) 
+0

你能告訴我們你的'channels'結構嗎? – dstepan

+0

@dstepan你去了,我只是編輯了顯示「頻道」的圖片:) –

回答

0

我的壞,我跳過了2名兒童(S):postIdentifier和downvotes :)

1

看起來像你的結構與您的Firebase查詢不符。您的結構是頻道>頻道>帖子>帖子>日期> userId。但是您嘗試的代碼是頻道>頻道>帖子>帖子> userId。 Firebase無法在該路徑上找到userId,因此什麼都不會發生。

嘗試下面的代碼,讓你更接近:

self.databaseRef.child("channels") 
       .child(Current.user.channel) 
       .child("posts/post") 
       .observeSingleEvent(type: .value, with: { (snapshot) in 


     }) 

我稍後編輯該代碼,讓你走得更遠,如果必要的。我現在不在我的Mac上。

相關問題