Is there any advantage of having atomic property f

2019-09-09 13:43发布

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

2条回答
该账号已被封号
2楼-- · 2019-09-09 14:12

Yes,

If you are using Atomic, it is thread safe.

查看更多
贪生不怕死
3楼-- · 2019-09-09 14:19

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?

查看更多
登录 后发表回答