Search code examples
iphoneobjective-cfile-ionsfilemanager

NSFileManager: Copy a file atomically?


in my iPhone projects, I am currently copying files using NSFileManager's -copyItemAtPath:toPath:error: method. 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:.


Solution

  • How do you use 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. Instances of NSFileManager are considered thread-safe when created using [[NSFileManager alloc] init].