writeToFile:atomically: what does atomically mean?

JonasG picture JonasG · Dec 17, 2011 · Viewed 17.1k times · Source

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.

Answer

Jack Danger picture Jack Danger · Dec 17, 2011

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.