Your code is close but let's take a look at what it's doing. Firebase strucures are always key: value pairs (e.g. think Dictionary) so this is valid
name: "Leeroy"
wheras this is not
"TestNode"
as you can see TestNode is not a key: value pair.
["TestNode", "Hello", "Test123"]
is also not valid as it's now an array of strings - not key: value pairs.
This is valid a valid key: value pair
user_0
name: "Leeroy"
because user_0 is the key and name: "Leeroy" is the value, which is also a key: value pair.
The reason your code isn't working as it's trying to write a single string, TestNode to Firebase without it being in a key: value format. So fix it by making the data a key: value pair (Dictionary) instead of a single string (on in your case a single string stored in an array)
let dict = [
"name": "Leeroy",
"food": "pizza"]
let testRef = self.ref.child("TestNode")
testRef.updateChildValues(dict) { (error, value) in
if error != nil {
return
} else {
}
}
This will result in the following structure being written to Firebase
TestNode
name: "Leeroy",
food: "pizza"
Firebase needs to know where you want data stored; when you tell it to add or update the pizza value in the TestNode/food node, it knows specifically where you want the data written.
An array of strings should not be directly written to Firebase as it will be just that, an array. Each element of the array would generally be associated with a node (key) to make each element a key: value pair. This is good form, makes your Firebase queryable and more maintainable.
While it may be tempting to use arrays in Firebase (because it can be done) - don't. It's not a concept that works well in NoSQL databases. See Don't Use Arrays and also this post and maybe this one as well for further reading.