plist 还是 NSUserDefaults 对于存储少量数据更有效?

发布于 2024-12-13 18:05:46 字数 171 浏览 4 评论 0原文

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

在这两种情况下,数据都是使用一些文件 IO 来持久保存的,因此磁盘访问应该是相似的。

然而,plist 似乎还需要做一些工作。

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.

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

However, the plist seems like a little more work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

星軌x 2024-12-20 18:05:46

NSUserDefaults 一个plist(这就是为什么只有plist类型可以存储在其中)。因此最终效率不会有太大差异(无论你的意思是什么)。您应该考虑在适当的地方保存这些数据。苹果表示,除非适合存储在 iCloud 中,否则不要将其保存在 Document 文件夹中;当用户备份设备时,它会被备份,并且会从用户的配额中扣除,因此您需要节省保留在那里的内容。

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

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.

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...

放赐 2024-12-20 18:05:46

在我看来,plist 比 NSuserDefaults 使用起来简单得多。毕竟,字典可以将自身保存为 plist。至于效率,它们应该与 NSUserDefaults 相同,将所有内容存储为 plist,但提供更多服务,例如与提供的一组键/值默认对相比,比较哪些键/值对已更改。

In my opinion, plist are much simpler to use than NSuserDefaults. Afterall, a dictionary can save itself as a plist. As for efficiency, they sould be the same as NSUserDefaults stores everything as a plist but provides more services such as comparing which key/values pair have changed compared to a provided set of key/values default pairs.

始于初秋 2024-12-20 18:05:46

您可能需要考虑使用 JSONKit 的 JSON。一些测试表明它比二进制plist更快,如果速度是您最关心的问题。该 API 非常简单,因为它在 NSDictionaryNSArray 上创建了一个类别。在这两个对象上调用 -(NSData *)JSONData 会返回一个可供保存的 NSData 对象。

You may want to consider JSON using JSONKit. Some tests show it's faster than a binary plist, if speed is your primary concern. The API is dead simple because it creates a category on NSDictionary and NSArray. Calling -(NSData *)JSONData on either of those objects returns an NSData object ready to save.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文