Is there any advantage of having atomic property for saving in keychains/userdefaults?

末鹿安然 提交于 2019-12-13 06:16:33

问题


For storing some values in NSUserDefaults / keychains is there any advantage of having atomic or non-atomic properties?


回答1:


The difference between "atomic" and "non-atomic" is that atomic requires that all of the data must be successfully written while "non-atomic" means "write as much as possible" (i.e. not necessarily all of it).

So for many things (e.g. small bits of data), there's not much of a practical difference between non-atomic or atomic.

But for larger blocks of data, then non-atomic vs. atomic actually makes a difference. Do you need to have the data that's written to be 100% perfect and complete, or can your app handle just some of whatever has been written to default or the keychain?




回答2:


Yes,

If you are using Atomic, it is thread safe.



来源:https://stackoverflow.com/questions/13728171/is-there-any-advantage-of-having-atomic-property-for-saving-in-keychains-userdef

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