Atomically: (BOOL)useAuxillaryFile


#1

I am struggling trying to understand what they two words mean.

NSString method:
writeToFile:atomically:encoding:error:

What does atomically mean in this method? and what is an auxillary file?


#2

On most operating systems, writing a file is not atomic (if the lights go out while the file is being written, it may be half written when the machine reboots). Renaming a file is atomic (if the lights go out, the file either has its old name or its new name when the machine reboots)

Thus, one way to make sure that you don’t end up with a corrupt file is to write it somewhere else and then move it into place. (This is especially useful if you are replacing an existing file – either you have the old version or the new one, but you never have half a file.)

So, if you pass YES for atomically, the string is written out to a file and then renamed to what you wanted it to be called:


#3

Thank you :slight_smile: