I am attempting to read a realtime db in firebase but my problem is the json is dynamic so using a swift file to define the layout isn’t going to work. I would like to use the data to update a tableview controller in the ultimate end. Any help would be greatly appreciated.
This is what the data looks like:
{
"Days": [
null,
{
"Chap": {
"1": "0",
"2": "0",
"3": "0",
"4": "0"
},
"Comp": "0"
},
{
"Chap": {
"5": "0",
"6": "0",
"7": "0",
"8": "0"
},
"Comp": "0"
}
]
}
This app is for reading through a book by chapters.
Here is what I have come up with so far but it isn’t working:
for n in begChapt...endChapt {
let myPath = "Yrly/Days/1/C/"
let myRef2 = ref.child(firUser!).child(myPath)
myRef2.observe(.value, with: {
snapshot in
let mItem = Repository(id: snapshot)
})
}
}
struct Repository {
let id: Int
}
func parseRepository(id: Int) -> Repository? {
guard let id = id[Int] as? Int else {
print("Couldn't convert id to an Int")
return nil
}
// TODO: parse the rest of the JSON...
return Repository(id: id)
}