plist或NSUserDefaults是否更有效地存储少量数据? [英] Is a plist or NSUserDefaults More Efficient for storing a small amount of data?

查看:99
本文介绍了plist或NSUserDefaults是否更有效地存储少量数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个项目,我可以采取任何一种方式,但我很好奇,如果使用plist来存储一些数据,或者比仅仅将plist保存在documents文件夹中效率更高或更低。数据大约是50个字符串/字典。

I can go either way on this for this project, but I'm curious if using a plist to store some data is going to be more or less efficient than just keeping a plist in the documents folder. The data is about 50 strings/dictionaries.

在这两种情况下,数据都会使用某些文件IO保留,因此磁盘访问应该类似。

In both cases the data gets persisted using some file IO so disk access should be similar.

但是,plist似乎还有点工作。

However, the plist seems like a little more work.

推荐答案

NSUserDefaults 一个plist(这就是为什么只有plist类型可以存储在其中)。因此,最终效率不会有太大差异(无论你的意思是什么)。您需要考虑的是适当以保留此数据。 Apple说,不要将它保存在Document文件夹中,除非它适合存储在iCloud中。它将在用户备份设备时备份,并将从用户的配额中减去,因此您需要节省您保留的内容。

NSUserDefaults is a plist (that is why only plist types can be stored in it). So ultimately there isn't going to be much difference in efficiency (whatever you mean by that). Your consideration should rather be where it is appropriate to keep this data. Don't keep it in the Document folder unless it is appropriate for storage in iCloud, says Apple; it will be backed up when the user backs up the device, and will subtract from the user's quota, so you need to be sparing of what you keep there.

在一个我自己的应用程序,我从RSS源下载一堆数据并将其呈现给用户,我将数据存储在用户默认值中,因为它是下次出现时应用程序持久状态的一部分。我的数据不是文件;这是应用程序的状态。这是我的推理,我建议你可以推理类似的行......

In one of my own apps, where I download a bunch of data from an RSS feed and present it to the user, I store the data in the user defaults, because it is part of the app's persistent state the next time it appears. My data isn't a document; it's the app's state. That's my reasoning, and I'd suggest you might reason along similar lines...

这篇关于plist或NSUserDefaults是否更有效地存储少量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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