我有以下功能,但它总是在
dispatchGroup.leave()语句,我不明白为什么。根据我在网上找到的信息,每个dispatchgroup.leave()都必须与dispatchgroup.enter()相关联,我相信我的函数就是这样。
self.kycrecords只包含1个元素(暂时)。
@IBAction func checkCustomerList(_ sender: Any) {
let dispatchGroup = DispatchGroup()
for kycRecord in self.kycRecords {
dispatchGroup.enter()
ApiManager.sharedInstance.postUserToArtemis(kycRecord) {(response, error) in
dispatchGroup.leave()
if error != nil {
kycRecord.kycStatus = "failed"
} else {
if response == true {
kycRecord.kycStatus = "passed"
} else {
kycRecord.kycStatus = "failed"
}
}
}
}
dispatchGroup.notify(queue: DispatchQueue.main, execute: {
print("done")
self.writeOutput()
})
}
它会崩溃并显示消息:
线程1:exc_bad_指令(代码=exc_i386_invop,子代码=0x0)