Samuel
Samuel

Reputation: 67

Can't retrieve data from Firestore

I am new to using Firestore, so I am still trying to understand it. I went to retrieve data from FireStore in a UICollectionView and there is no data. The method says that no data exists at the Firestore reference; I have tried "googling" the problem and can't find the solution. Here is a screenshot of my database structure:

I want to retrieve all the documents from the "MenuEntries" collection in realtime. Here is the code I have tried:

 func retrieveData()  {
   let reference = Firestore.firestore().collection("Week1").document("Menu").collection("MenuEntries")
    reference.getDocuments { (snapshot, error) in
        if(snapshot!.isEmpty){
            print("There is no data")
        }else{
        for document in snapshot!.documents {
            let temp = Menu(dictionary: document.data())
         print(temp)
            self.menu.append(temp)

      }
    }
}
}

Upvotes: 1

Views: 515

Answers (1)

vitooh
vitooh

Reputation: 4262

There is nice example here. Just mark Swift to see code.

Comparing your code it do not catch parameter error and it do not print directly data as well.

I suggest to try with the example from the Google tutorial if you get some data or error there.

I hope this will help!

Upvotes: 1

Related Questions