Adrien Zier Adrien Zier - 1 month ago 78
Swift Question

Firebase Swift 3 get list of child in a array

I'm trying to the get a list data from the firebase database then convert as a array. I looked many example online but never managed to work (as far as I know) the code below is the closet I could get with 1 error.

ref.child("").observe(.childAdded, with: { (snapshot) -> Void in

var newItems = [FDataSnapshot]() //Error: Use of unresolved identifier 'FDataSnapshot'

for item in snapshot.children {
newItems.append(item as! FDataSnapshot)
}

})


I just cant find a answer since those past 2 days.

Thanks in advance for helping!

Answer

Try this:-

ref.child("").observe(.childAdded, with: { (snapshot) in

    var newItems = [FIRDataSnapshot]() 

    for item in snapshot.children {
        newItems.append(item as! FIRDataSnapshot)
    }

})