2017-04-03 3 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子(複数可)をスキップ:postIdentifierとdownvotes :)

1

はあなたの構造のように見えますFirebaseのクエリと一致しません。あなたの構造はチャンネル>チャンネル>投稿>投稿>日付>ユーザーIDです。しかし、あなたが試みているコードはchannels> channel> posts> post> userIdです。 FirebaseはそのパスでuserIdを見つけることができないため、何も起こりません。

は、あなたが近づくために以下のコードを試してみてください。

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


     }) 

必要であれば、私は、さらに一緒にあなたを得るために、後でこのコードを編集します。私は今、私のマックではない。

関連する問題