試試這個代碼,我希望這將這樣的伎倆
// U can use this to set value to your database
func setValue() {
let myRef = FIRDatabase.database().reference().child("Your path")
let valueForChild: String = "newValue"
let newValue = ["childName": valueForChild] as [String: Any]
myRef.setValue(newValue) { (error, ref) in
if error != nil {
print(error?.localizedDescription ?? "Failed to update value")
} else {
print("Success update newValue to database")
}
}
}
// or this to update new value to your database
func updateValue() {
let myRef = FIRDatabase.database().reference().child("Your path")
let valueForChild: String = "newValue"
let newValue = ["childName": valueForChild] as [String: Any]
myRef.updateChildValues(newValue) { (error, ref) in
if error != nil {
print(error?.localizedDescription, "Failed to update value")
} else {
print("Success update newValue to database")
}
}
}
確保你'ref'不爲零,最有可能是。 – Dravidian
@Dravidian我應該在完成還是之前檢查? –
嘗試之前打印.... – Dravidian