I\'m using the following code to do some complex background operations from a newly launched view controller
let globalQueue = DispatchQueue.global()
glob
Create the dispatch work item.
//create the dispatch work item
var disptachWorkItem:DispatchWorkItem?
Now put the complex task in dispatch work item.
dispatchWorkItem = DispatchWorkItem {
//Some complex job
}
Execute the Work on default global queue.
DispatchQueue.global().async(execute: dispatchWorkItem!)
You can find out when the viewController is being dismissed.
DispatchQueue.global.async {
dispatchWorkItem?.cancel()
}
presentingViewController?.dismissViewController(animated: true, completion: nil)