将调度组与循环中的调用一起使用有什么好处?我使用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, limit: limit, calls: calls)
}
它似乎工作正常,但我想知道调度组是否有一些好处或这种方法存在缺陷。