Hi I'm trying to get the numOfVids in Firebase db so I can return that number in my numberOfItemsInSection. But it returns 0 instead of 6. I know it returns 0 because it's reading the empty variable instead of the one in the observeSingleEvent.
Is there any way for me to get the modified numOfVids instead of the empty numOfVids?
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
var numOfVids = Int() // 0
let videosRef = FIRDatabase.database().reference().child("users/\(currentUserID)/videos")
videosRef.observeSingleEvent(of: .value, with: { (snapshot) in
//get user value
numOfVids = Int(snapshot.childrenCount)
print(numOfVids) //prints 6
})
return numOfVids //returns 0
}
Thank you in advance!