in Education by
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)

1 Answer

0 votes
by
You need to reload the collectionView as the call to firestore is asynchronous for document in querySnapshot!.documents { print("\(document.documentID) => \(document.data())") self.items.append(document.data()["title"] as! String) } self.collectionView.reloadData()

Related questions

0 votes
    trying to change method to update the data, because with reloadData have lag let oldIns = insertCounter ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Why does UIImageView remove from Array when I used removeFromSuperview() with Swift? // display UIImageView var ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I have a class which has 2 sets of getter & setters. 1 set is the traditional type. These work ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 30, 2022 in Education by JackTerrance
0 votes
    In my password reset function the user can put in whatever he/she wants. It does not even needs ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I've searched Apple's documentation, open source projects, and Google, and I cannot seem to find any ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm relatively new to Swift and Firebase, so I'm not very familiar with the intricacies of how ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    Can anyone help me, Im trying to make a simple app where you touch the screen and 4 images are ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Can anyone help me, Im trying to make a simple app where you touch the screen and 4 images are ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I followed this thread to override -preferredStatusBarStyle, but it isn't called. Are there any options that ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am working on a code pen and am having an issue where initially my main element would be exactly ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: jQuery in Greasemonkey 1.0 conflicts with websites using jQuery (3 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I have developed a website that queries NASA's image API. The website works fine on my desktop browser. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I'm attempting to build an email scraper that takes in a csv file of urls, and returns them with ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I want to make use of tabs layout within tabs layout. I am using Material Design lite which has ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I need to count daily orders per user. The data may arrive late for quite a long time. So i ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
...