2016-09-28 63 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?您是否無法爲您的數據庫設置值?還請詳細說明您的問題,並提供更多信息 – 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是,你要尋找的ID和數據將存儲在postRef中指定的路徑中。

希望這會有所幫助。