I've got a function that runs on a background thread and downloads files:
func downloadFiles(remoteFolder rf:String, localFolder lf:String, completion: @escaping (_ success:Bool, _ err: String) -> Void) {
DispatchQueue.global(qos:.background).async {
...
DispatchQueue.main.async {
completion(successBool, errorMsg)
}
}
}
It's called by my main ViewController
:
myDownloadClass.downloadFiles(remoteFolder: rf, localFolder: lf, completion: { (success, error) in
... //More stuff here
}
Is there a way to temporarily switch back to the main thread (and with that also to the VC) in downloadFiles
, so I can add the name of the file that's next in the download list to an e.g. UIAlertController
but without tripping off everything that should be done after downloading everything actually finished ("More stuff here")?
I'm using Xcode 13 with Swift 5 and iOS 13.