Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSFileManager removeItemAtPath locks main thread

I'm working on an app that can remove large amounts of files. When I invoke the NSFileManager's removeItemAtPath method, the app's UI locks until the operation finishes (this can take a while).

I tried fixing this by invoking the method using performSelectorInBackground but it didn't work.

Any ideas?

Thanks in advance.

like image 241
mikywan Avatar asked Dec 19 '11 14:12

mikywan


1 Answers

You could try using GCD to do it in a background thread.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
  [[NSFileManager defaultManager] removeItemAtPath:path];
});
like image 134
Randall Avatar answered Nov 01 '22 10:11

Randall