Я пытаюсь вызвать функцию self.setupDummyCards()
после того, как self.cardViewModels.append(user.toCardViewModel())
завершил добавление всех пользователей к CardViewModels
массиву, хотя я не могу понять, где ее разместить?
fileprivate func fetchUsersFromFirestore() {
guard let uid = Auth.auth().currentUser?.uid else { return }
Firestore.firestore().collection("Users").document(uid).collection("Following").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
let d = document.data()
d.forEach({ (key: String, value: Any) in
Database.firestorefetchUserForTinderCardWithUID(uid: key, completion: { (user) in
self.cardViewModels.append(user.toCardViewModel())
//below it is called after each user is appended, meaning it appends the same users again and again until the last user is add
self.setupDummyCards()
})
//here is called before self.cardViewModels.append(user.toCardViewModel())
})
//here is called before self.cardViewModels.append(user.toCardViewModel())
}
//here is called before self.cardViewModels.append(user.toCardViewModel())
}
//here is called before self.cardViewModels.append(user.toCardViewModel())
}
//here is called before self.cardViewModels.append(user.toCardViewModel())
}