2016-09-28 18 views
1

保存した後にオブジェクトのIDを取得し、このオブジェクトを使用してイメージを保存するためにこのメソッドを使用して日付を保存しようとしていますが、このメソッドは機能しません。オブジェクトIDを取得するのですか?この場合Firebaseメソッドが機能しません

postRef.setValue("I'm writing data", withCompletionBlock: { 
     (error, ref) in 
     if (error != nil) { 
      Constant.displayAlert(view: self, title:"", Message: "RRRR") 
     } else { 
      Constant.displayAlert(view: self, title:"", Message: "RRRR") 
     } 
    }) 
+0

どのオブジェクトIDですか?あなたのDBに値を設定できませんか?さらに詳しい情報であなたの質問を詳述してください – Dravidian

答えて

2

、あなたはpostRefの直接の子としてデータを保存している、あなたはpostRefの場所ですべてのデータを上書きしてしまいます。あなたは詳細の多くを残してきたが、

が、私の理解では次のような使用できます。私の意見では

insertionRef = postRef.childByAutoId() // inserts a child by an auto generated Id 
requiredId = insertionRef.key // returns a string 
insertionRef.setValue("I'm writing data", withCompletionBlock: { 
    (error, ref) in 
    if (error != nil) { 
     Constant.displayAlert(view: self, title:"", Message: "RRRR") 
    } else { 
     Constant.displayAlert(view: self, title:"", Message: "RRRR") 
    } 
}) 

を、 requiredIdは、あなたが探しているイドと、あなたのデータであり、 postRefで指定されたパスに格納されます。

これが役に立ちます。

関連する問題