Looping over array to do API calls with on the main thread

I'm trying to loop over the an array of self.kycRecords and execute a function after the loop has been completed.

@IBAction func checkCustomerList(_ sender: Any) {
    DispatchQueue.main.async {
        for kycRecord in self.kycRecords {
            ApiManager.sharedInstance.postUserToArtemis(kycRecord) {(response, error) in
                DispatchQueue.main.async {
                    if error != nil {
                        kycRecord.kycStatus = "failed"
                    } else {
                        kycRecord.kycStatus = "passed"
                    }
                }
            }
        }
    }
    self.writeOutput()
}

Right now self.writeOutput() gets triggered straight away. How do I make it wait until the loop is completed?