I am wondering what the atomically:
parameter stands for in the writeToFile:atomically:
method (-[NSArray writeToFile:atomically:]
for example). It is common to pass YES
for atomically:
, but I don't know what it means.
Atomic file guarantees file integrity by ensuring that a file has been completely written and sync'd to disk before renaming it to the original file.
Having stored the contents of a file in an NSData object, that data may subsequently be written out to a new file using the createFileAtPath method: databuffer = [filemgr contentsAtPath: @"/tmp/myfile. txt" ]; [filemgr createFileAtPath: @"/tmp/newfile. txt" contents: databuffer attributes: nil];
An 'atomic write' is one where you are guaranteed to have either a correct, complete write to the file or an error. There's no chance that, say, half of the write will work and then something bad happens (lost power, drive crash, etc) and the rest of the write fails. It's all or nothing. This is generally what you want.
atomically
If YES, the data is written to a backup file, and then—assuming no errors occur—the backup file is renamed to the name specified by path; otherwise, the data is written directly to path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With