【发布时间】:2019-12-20 15:29:12
【问题描述】:
我现在遇到了一个非常奇怪的问题,我不知道为什么会发生这种情况。
首先我从我的 Cloud-FirestoreDB 中检索一些 documents。这工作得很好。
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()
}
正如你在上面的函数中看到的那样,我也是.append 我的wishListTitlesArray。但是,如果我尝试访问其中的数据,则不会发生任何事情..
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)
}
}
}
}
}
现在它正在打印print("yikes"),所以它甚至没有进入for-loop。
我还尝试打印func retrieveUserDataFromDB 末尾的所有元素,但这也无济于事。它没有崩溃或显示任何错误。
可能只是一个愚蠢的错误,但如果有人知道为什么会发生这种情况,我将非常感激!
【问题讨论】:
标签: ios arrays firebase arraylist google-cloud-firestore