Suppose I use a different SDK (with which I have no control) with an API that imports 1 file asynchronously and causes completion to complete. The following is an example API.
func importFile(filePath: String, completion: () -> Void)
I need to import 10 files (one by one) using this API, but I need to cancel it, for example. after files 1,2,3 were successfully imported while file 4 is being imported, I want to be able to undo the whole set of operations (import of 10 files) so that file 4 is completed (since it is already running), but Files 5-10 will no longer be imported.
In addition, I also need to report on the progress of the import. When file 1 was successfully imported, I should report 10% progress (1 out of 10 completed).
How can i achieve this?
I am considering using NSOperationQueue with 10 NSOperations, but it seems like a progress report will be difficult.
source
share