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()

Need to call tableView.reloadData() after TimeLine Collection ViewController.allProd= all in loading function

Oleg Soloviev2022-02-05 21:30:13

@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:13