writeToFile:atomically: what does atomically mean?

谁都会走 提交于 2019-11-30 11:58:17

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/8548293/writetofileatomically-what-does-atomically-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!