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.
Asked
Active
Viewed 1.8k times
61

JonasG
- 9,274
- 12
- 59
- 88
2 Answers
105
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.

Jack Danger
- 1,406
- 1
- 9
- 7
-
13The old file will not be changed or removed until the new version is completely on the disk. – Walt Sellers Oct 10 '12 at 17:32
-
5Upvote for "This is generally what you want.", which Apple docs leaves out – William Entriken Oct 05 '14 at 21:04
40
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.

Darko Kenda
- 4,781
- 1
- 28
- 31