IOS file management nsfilemanager nsfilehandle

Source: Internet
Author: User

Http://liuxing8807.blog.163.com/blog/static/9703530520133413353291/

Http://www.cnblogs.com/jay-dong/archive/2013/01/21/2870414.html

Shocould noted: http://useyourloaf.com/blog/2011/06/12/nsfilemanager-defaultmanager-is-not-thread-safe.html

Nsfilemanager * filemanager = [nsfilemanager defaultmanager];

If ([filemanager fileexistsatpath: sourcefile]) {

Nserror * error = nil;

If (! [Filemanager copyitematpath: sourcefile

Topath: destfile

Error: & error]) {

// Deal with error

}

}

The methods of the shared nsfilemanager object can be called from multiple threads safely. however, if you use a delegate to receive comprehensions about the status of move, copy, remove, and link operations, you shoshould create a unique instance
Of the File Manager object, assign your delegate to that object, and use that file manager to initiate your operations.

In iOS and Mac OS X V 10.5 and later you shoshould consider using [[nsfilemanager alloc] init] rather than the singleton method defaultmanager. instances ofnsfilemanager are considered thread-safe when created using [[nsfilemanager alloc] init].

This means that if your application ends up using the nsfilemanager Singleton from more than one thread you may get some unexpected results or even end up with your upted files in your file system. the thread safe version of the above code fragment
Wocould look like this:

Nsfilemanager * filemanager = [[nsfilemanager alloc] init];

If ([filemanager fileexistsatpath: sourcefile]) {

Nserror * error = nil;

If (! [Filemanager copyitematpath: sourcefile

Topath: destfile

Error: & error]) {

// Deal with error

}

}

[Filemanager release];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.