Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is NSFileManager thread safe?

Is it ok to get an instance of NSFileManager via defaultManager and use it outside the main queue?

Is this code ok?

dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(q, ^{

    NSFileManager *fm = [NSFileManager defaultManager];

});
like image 775
cfischer Avatar asked Mar 22 '13 13:03

cfischer


People also ask

What is NSFileManager?

The NSFileManager class provides convenient access to a shared file manager object that is suitable for most types of file-related manipulations. A file manager object is typically your primary mode of interaction with the file system. You use it to locate, create, copy, and move files and directories.

Is mutable array thread safe?

Mutable objects are generally not thread-safe. To use mutable objects in a threaded application, the application must synchronize access to them using locks.

Is Nsdictionary thread safe?

According to Apple's notes, the NSMutableDictionary is not safe if it is accessed from multiple threads simultaneously. To tackle this problem, one may choose to use a lock or a serial queue to synchronise access to a NSMutableDictionary.

What is thread safe in iOS?

Thread Safety APIs in iOSBy creating a queue of tasks where only one task can be processed at any given time, you are indirectly introducing thread safety to the component that is using the queue.


1 Answers

From NSFileManager Class Reference:

The methods of the shared NSFileManager object can be called from multiple threads safely. However, if you use a delegate to receive notifications about the status of move, copy, remove, and link operations, you should create a unique instance of the file manager object, assign your delegate to that object, and use that file manager to initiate your operations.

like image 197
Adam Avatar answered Sep 28 '22 08:09

Adam