在我的 iPhone 项目中,我目前正在使用 NSFileManager
的 -copyItemAtPath:toPath:error:
方法复制文件。但是,文档没有提及任何关于原子性的内容,因此如果我的应用程序试图读取当前正被另一个线程替换的文件,我可能会遇到麻烦。
有没有办法以原子方式复制或替换文件?我正在搜索类似 NSData
的 -writeDataToFilr:atomically:
。
最佳答案
你如何使用 NSFileManager
?根据docs ,它说了以下内容:
In iOS and Mac OS X v 10.5 and later you should consider using
[[NSFileManager alloc] init]
rather than the singleton methoddefaultManager
. Instances ofNSFileManager
are considered thread-safe when created using[[NSFileManager alloc] init]
.
关于iphone - NSFileManager:以原子方式复制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4689455/