0

I need to do an API call and wait until I get response back before returning the value.

This however won't compile:

func doKYCCheckForCustomer(kycRecord: KYCRecord) -> Bool {
    ApiManager.sharedInstance.postUserToArtemis(kycRecord) {(response, error) in
        DispatchQueue.main.async {
            if error != nil {
                // Error on doing kyc check
                print(0)
                return false
            } else {
                // No error on doing kyc check
                print(1)
                return true
            }
        }
    }
}

The error Xcode is telling me is:

Unexpected non-void return value in void function

I don't think this is a void function. It returns a boolean so why is Xcode complaining about this?

I'm looping over a bunch of records to do this API call for so I need to make sure that the previous one is finished before executed a new call.

Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67
  • 1
    Please [search on the error](https://stackoverflow.com/search?q=%5Bswift%5D+Unexpected+non-void+return+value+in+void+function) before posting. This has been covered many times before. – rmaddy Jul 12 '18 at 06:11
  • Usually, when facing such a case, you would not be able to -directly- return a value from a function. I would suggest that you should follow the approach of making a callback for the method instead (using `@escaping` closure). – Ahmad F Jul 12 '18 at 06:12

0 Answers0