Home>
static func creatUserTimeLineProducts(completion: @escaping ([Product]) -> ()) {
firestore.firestore()
//get a list of Stores
.collection("stores")
.getDocuments { stores, error in
print("Stores: \(stores!.count)")
//loop through all Stores
for store in stores!.documents {
let storeRef= store.reference
//go to Products
storeRef.collection("products")
.getDocuments { products, error in
print("Products: \(products!.count)")
//get all Products
let prods= products?.documents.compactMap({ Product(productDict: $0.data() )})
for prod in prods! {
FBDataBase.allProdArray.append(prod)
}
completion(FBDataBase.allProdArray)
}
}
}
}
func loadind() {
FBDataBase.creatUserTimeLineProducts { all in
TimeLineCollectionViewController.allProd= all
}
TimeLineCollectionViewController.allProd= FBDataBase.allProdArray
print("Number of Items Buyers loading: \(TimeLineCollectionViewController.allProd.count)")
}
override func loadView() {
super.loadView()
switch AuthAccount.authProfile {
case .store:
FBDataBase.creatDB { prodArray in
TimeLineCollectionViewController.prodArray= prodArray
}
case .user:
loadind()
@OlegSoloviev, good afternoon and under this question, Oleg! Thanks, I'll try now. I'll post the result.
Максим Артемов2022-02-05 21:30:13@OlegSoloviev, I tried it, it doesn't work. Still getting zero
Максим Артемов2022-02-05 21:30:13@OlegSoloviev, in general, I solved the problem. I took completion up a level, to the last for in. I think this is due to the fact that the function is complex, consisting of request attachments to the Firestore, which are themselves asynchronous.
Максим Артемов2022-02-05 21:30:13Related questions
- ios - i want to return to the first initial screen after logging out
- ios - transition screen in authentication with firebase
- xcode - how to read tables in firebase-realtime database
- Command CompilesWiftSources Failed WITH A Nonzero Exit Code in MessageKit
- ios - data of authauth () currentuser? uid cannot be deleted even if the application is deleted
- xcode - firestore custom objects
- [ios] effect of setting enable bitcode to false
- swift : How do I get an array?
- xcode - firebase ui freezes when building on the actual machine
Need to call tableView.reloadData() after TimeLine Collection ViewController.allProd= all in loading function
Oleg Soloviev2022-02-05 21:30:13