I'm doing file transfers using the Dropbox API v2. The methods include closures where the success of the transfer is available, but the method I've written to execute the transfer always returns before the closures complete and I can never set a property. The transfers work fine, I simply want to download three separate files and then put up an alert to tell the user of success.
I've looked through a bunch of similar questions on SO but so far no one has a solution. Is it not possible to capture a value in the closure and pass it to another class?
I've tried setting external properties, static properties and using intermediate functions. Nothing works. The method is:
func downloadFromDropbox(downloadFileName : String) -> Bool {
var success = false
if let client = DropboxClientsManager.authorizedClient {
//file and directory stuff here
client.files.download(path: dropFileName, overwrite: true, destination: destination)
.response { response, error in
if let response = response {
print(response)
success = true
print("success in the block: \(success)")//this prints correctly
} else if let error = error {
print(error)
success = false
}//if let response else
}//.response block
.progress { progressData in
//print(progressData)
}//.progress
} else {
//login stuff here
}//if let client else
print("and success before the return: \(success)") //this does not work-always false
return success //this does not work-always false
}//downloadFromDropbox
Any guidance would be appreciated.Swift 3, IOS 10, Xcode 8.0