NSFileManager removeItemAtPath blocks the main thread

I am working on an application that can delete a large number of files. When I call the removeItemAtPath NSFileManager method, the user interface of the application is blocked until the operation is completed (this may take some time).

I tried to fix this by calling using performSelectorInBackground method, but it did not work.

Any ideas?

Thanks in advance.

+5
source share
1 answer

You can try using GCD to do this in the background thread.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
  [[NSFileManager defaultManager] removeItemAtPath:path];
});
+1
source

All Articles