NSUserDefaults的最佳实践同步 [英] Best Practice for NSUserDefaults synchronize

查看:110
本文介绍了NSUserDefaults的最佳实践同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我向plist写任何东西时,我都在使用 [[NSUserDefaults standardUserDefaults] synchronize] 。这有点矫枉过正吗?或者这样做会产生不利影响吗?

I'm using [[NSUserDefaults standardUserDefaults] synchronize] each time I write anything to the plist. Is that overkill? Or are there adverse effects in doing this?

推荐答案

是的它可能有点矫枉过正,但在一个简单的应用程序中你会发现性能受到影响?如果您只是在基本用户交互之后保存,例如用户选择其设置,则可能不会。更频繁地调用同步的好处是,如果您的应用程序可能崩溃并且您保存的信息很重要,否则iOS会定期为您保存。

Yes it may be overkill but in a simple application will you notice a performance hit? probably not if you are only saving after basic user interaction such as the user selecting their settings. The benefit to calling synchronize more often is if your application may crash and the information you are saving is important, otherwise iOS will save it for you periodically.

这篇关于NSUserDefaults的最佳实践同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆