I am having a really weird problem at the moment and I have no clue why this happens.
First I retrieve some documents from my Cloud-FirestoreDB. This works perfectly fine.
func retrieveUserDataFromDB() -> Void {
// local mutable "WishList" var
var wList: [Wish] = [Wish]()
let db = Firestore.firestore()
let userID = Auth.auth().currentUser!.uid
db.collection("users").document(userID).collection("wishlists").order(by: "listIDX").getDocuments() { ( querySnapshot, error) in
if let error = error {
print(error.localizedDescription)
}else {
// get all documents from "wishlists"-collection and save attributes
for document in querySnapshot!.documents {
let documentData = document.data()
let listName = documentData["name"]
let listImageIDX = documentData["imageIDX"]
// if-case for Main Wishlist
if listImageIDX as? Int == nil {
self.wishListImagesArray.append(UIImage(named: "iconRoundedImage")!)
self.wishListTitlesArray.append(listName as! String)
// set the drop down menu's options
self.dropDownButton.dropView.dropDownOptions.append(listName as! String)
self.dropDownButton.dropView.dropDownListImages.append(UIImage(named: "iconRoundedImage")!)
}else {
self.wishListTitlesArray.append(listName as! String)
self.wishListImagesArray.append(self.images[listImageIDX as! Int])
self.dropDownButton.dropView.dropDownOptions.append(listName as! String)
self.dropDownButton.dropView.dropDownListImages.append(self.images[listImageIDX as! Int])
}
// create an empty wishlist
wList = [Wish]()
self.userWishListData.append(wList)
// reload collectionView and tableView
self.theCollectionView.reloadData()
self.dropDownButton.dropView.tableView.reloadData()
}
}
}
// un-hide the collection view
self.theCollectionView.isHidden = false
getWishes()
}
As you can see in the function above I also .append my wishListTitlesArray. However if I try to access the data inside of it nothing happens..
func getWishes (){
let db = Firestore.firestore()
let userID = Auth.auth().currentUser!.uid
var counter = 0
print("yikes")
for list in self.wishListTitlesArray {
print("yeet")
db.collection("users").document(userID).collection("wishlists").document(list).collection("wünsche").getDocuments() { ( querySnapshot, error) in
if let error = error {
print(error.localizedDescription)
}else{
var wList = self.userWishListData[counter]
for document in querySnapshot!.documents {
let documentData = document.data()
let wishName = documentData["name"]
wList.append(Wish(withWishName: wishName as! String, checked: false))
counter += 1
print("hi")
print(wishName as! String)
}
}
}
}
}
Right now it is printing the print("yikes") so it is not even going inside the for-loop.
I also tried printing all the elements in the end of func retrieveUserDataFromDB but that doesn't doing anything either. It is not crashing or showing any error.
Probably just a stupid mistake but if anyone has any idea why this happens I would be very grateful!