writeToFile:atomically: what does atomically mean?

IosObjective CCocoa TouchAtomicWritetofile

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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.

Solution 2 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJonasGView Question on Stackoverflow
Solution 1 - IosJack DangerView Answer on Stackoverflow
Solution 2 - IosDarko KendaView Answer on Stackoverflow