I am trying to create a child in an empty firebase database using Swift, the code is running without any errors but I don't see the changes in the database. the code:
let ref = Database.database().reference()
ref.child("Branches")
I am trying to create a child in an empty firebase database using Swift, the code is running without any errors but I don't see the changes in the database. the code:
let ref = Database.database().reference()
ref.child("Branches")
You're not adding values to the database.
In Firebase, you create additional childs as soon as you set new values.
You can use setValue
or updateChildValues
to add values.
Example:
let ref = Database.database().reference().child("branches")
let values = ["any_key" : "any_value"]
ref.updateChildValues(values) { (err, reference) in
// handle errors or anything related to completion block.
}
Docs: https://firebase.google.com/docs/database/ios/read-and-write
Note: Make sure you configured everything correctly: https://firebase.google.com/docs/database/ios/start
It's depend on your database structure let suppose you create
{
"users": {
"uid": userID,
"username": "string"
}
}
this time data then you can get it as you mention in your question
var ref: DatabaseReference!
ref = Database.database().reference()
self.ref.child("users").child(user.uid).setValue(["username": username])