调度组与循环调用

问题描述

在循环中使用调度组有什么好处? 我使用 alamo fire 作为我的网络层。这种情况是我想分块从服务器获取数据,一旦所有调用完成,我就可以继续前进。我真的需要使用调度组或简单的循环调用吗?

for _ in 1...calls {
            callFetchTransaction(offset: self.offset,limit: self.transactionsLimit,calls: calls)
        }

这就是我的函数中的内容

var listofIdsToSort = [String:Date]()
func callFetchTransaction(offset:Int,limit:Int,calls:Int) {
    TransactionsModel.reportTransactions(offset: offset,limit: limit,success: { (transactions) in
        ACTIVITYCALL += 1
        print("CurrentOffset \(offset),with limit\(limit)")
        print("ACTIVITY CALL \(ACTIVITYCALL)")
        for transaction in transactions {
            self.listofIdsToSort[transaction.id!] = transaction.createdAt!
        }
        if ACTIVITYCALL == calls {
           TransactionsModel.assignSequenceNumbers(dictOfIds: self.listofIdsToSort) {
                self.didCompleteProgressAndSync(duration: 2.0)
                print("sync time after --- \(Date().timeIntervalSince1970)")
            }
            return
        } else if ACTIVITYCALL < calls {
            self.currentSyncingProgress += self.perActivityPercentage
            dispatchQueue.main.async {
                self.updateProgressBar(value: self.currentSyncingProgress)
            }
        }
    }) { (response,statusCode) in
        self.callFetchTransaction(offset: offset,calls: calls)
    }
 

它似乎工作正常,但我想知道这种方法是否有调度组的一些好处或缺陷。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)