Reputation: 2025
I have a firebase ref and I want to update the ref of the firebase but my app crashes when ever I try it Could not cast value of type '__NSCFBoolean' (0x2106be078) to 'NSDictionary'
my ref looks like this below
Database.database().reference(forLastMsg: championId).child(toID).updateChildValues(withValues)
Database.database().reference(forLastMsg: toID).child(championId).updateChildValues(withValues)
even using setValue
crashes the app too.
I am actually constantly listning to the refs that is been updated so on valueChange
for snapshot in snapshot.children {
let receivedMessage = (snapshot as! DataSnapshot).value as!
NSDictionary
...
Upvotes: 0
Views: 99
Reputation: 100503
To update
let newVal = //// some dictionary
// you may add komal_xyz as dynamic according to your logic
Database.database().reference().child("komal_xyz/\(id)").updateChildValues(newVal) { (err, ref) in
}
To listen
Database.database().reference().child("komal_xyz/\(id)").observe(.value) { (ref) in
//
let res = ref.value as! [String:Any]
}
Upvotes: 0
Reputation: 390
You have to update it in such way
let updateDatabase = databaseReference.child("something").child(someId)
let data = [
"boolValue": myBoolean,
"dateUpdated": Date().toSeconds()
] as [String : Any]
updateDatabase.updateChildValues(data)
Upvotes: 1