如何最好地存储我的数据

发布于 2024-10-08 22:54:34 字数 222 浏览 1 评论 0原文

我有一个包含近 1000 个类实例的数组,每个实例都有大约 5 个与其关联的短字符串(<100 个字符)。在我的应用程序中,我经常从数组中随机选择一个对象,很少但偶尔会列出数组中的所有对象。

我倾向于使用 .plist 来存储数据,以便在开始时全部读入,但是在这种情况下这真的比使用 SQLite 更好吗?

现在,数组是静态的,尽管我将来可能想添加添加对象的功能。不过,这种情况只会偶尔发生。

I have an array with close to 1000 instances of a class, each of which has about 5 short strings (<100 chars) associated to it. In my app, I randomly select an object from the array frequently, and rarely but occasionally list all of the objects in the array.

My inclination is to use a .plist to store the data, so that it is all read in at the start, but is this really better than using SQLite in this case?

Right now, the array is static, though I may want to add the ability to add objects in the future. This would only happen occasionally, though.

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

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

发布评论

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

评论(4

双手揣兜 2024-10-15 22:54:34

我想到目前为止我对这个问题的解释与其他人不同。对我来说,听起来他在构建应用程序时拥有数据,并且想知道加载它的最佳方式。到目前为止给出的答案是关于如何从正在运行的应用程序中保存它。

对于这么多数据,使用 SQLite 会更快,特别是当您只需要一个随机对象时。然而,使用 plist 更容易实现和编辑。

I think I interpretted this question differently than everyone else so far. To me, it sounds like he has the data when he is building the application and wants to know the best way to load it. The answers given so far are about how to save it from the running app.

For that much data, using SQLite would be faster, especially when you only need a random object. However, using a plist is easier to implement and edit.

聽兲甴掵 2024-10-15 22:54:34

使用 XMLSerialization 怎么样?

How about using XMLSerialisation?

一场春暖 2024-10-15 22:54:34

可以多走几条路。最简单的方法是将数组写入用户的文档目录。看看 NSArray,特别是 - (BOOL)writeToFile:(NSString *)pathatomically:(BOOL)flag。您可以在 Apple 的存档和序列化编程指南中找到许多见解: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Archiving/Archiving.html%23//apple_ref/doc/uid/10000047i< /a>

然而,使用 CoreData 也可以获得很多好处。也许值得您花一些时间至少了解一下表面,看看好处是否超过实施时间。

You could take a few routes. The easiest would be to simply write out the array to the user's documents directory. Look at NSArray, in particular - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag. You can find many insights in Apple's Archives and Serializations Programming Guide: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Archiving/Archiving.html%23//apple_ref/doc/uid/10000047i

However, there is a lot to be gained by using CoreData, too. It may be worth your while to at least scrape the surface and see if the benefits outweigh the implementation time.

红墙和绿瓦 2024-10-15 22:54:34

我建议您也研究一下 JSON 格式。 http://code.google.com/p/json-framework/

I'd recommend you also look into JSON formatting. http://code.google.com/p/json-framework/

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