简体   繁体   English

NSFileManager:原子复制文件?

[英]NSFileManager: Copy a file atomically?

in my iPhone projects, I am currently copying files using NSFileManager 's -copyItemAtPath:toPath:error: method. 在我的iPhone项目中,我目前正在使用NSFileManager-copyItemAtPath:toPath:error:方法复制文件。 However, the docs so not say anything about atomicity, so I might run into trouble if my app tries to read a file that is currently being replaced by another thread. 但是,文档没有说明原子性,所以如果我的应用程序试图读取当前被另一个线程替换的文件,我可能会遇到麻烦。 Is there a way to copy or replace a file atomically? 有没有办法以原子方式复制或替换文件? I am searching for something like NSData 's -writeDataToFilr:atomically: . 我正在寻找类似NSData-writeDataToFilr:atomically: .

How do you use NSFileManager ? 你如何使用NSFileManager According to the docs , it says the following: 根据文档 ,它说如下:

In iOS and Mac OS X v 10.5 and later you should consider using [[NSFileManager alloc] init] rather than the singleton method defaultManager . 在iOS和Mac OS X v 10.5及更高版本中,您应该考虑使用[[NSFileManager alloc] init]而不是单例方法defaultManager Instances of NSFileManager are considered thread-safe when created using [[NSFileManager alloc] init] . 使用[[NSFileManager alloc] init]创建时, NSFileManager实例被认为是线程安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM