When you start the application, you should get a line from the Firestore documents and write to an array, (array)
var items = [String]()
override func viewDidLoad() {
let db = Firestore.firestore()
db.collection("cities").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
print("\(document.documentID) => \(document.data())")
self.items.append(document.data()["title"] as! String)
}
}
}
}
then in the cell creation function, the text should be changed to a line from the array.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! colCell
print(self.items)
cell.myLabel.text = self.items[indexPath.item]
return cell
}
But the array with strings from the firestore is not updated in the cell creation function. Why?
(I printed out array in viewDidLoad and in cell, it's updated in viewDidLoad and not updated in cell)
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)