在Objective-C中存储和加载大量数据的最佳方法 [英] Best way to store and load large amount of data in Objective-C

查看:70
本文介绍了在Objective-C中存储和加载大量数据的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用大量数据的应用程序,例如〜100个条目,每个条目包含多个图像,> 250个单词的文本和多个1个单词/字符值。

I'm in the process of making an app that will use a lot of data, e.g ~100 entries, each containing several images, >250 words of text and numerous 1 word/ character values.

我只是想知道在目标c中执行此操作的最佳做​​法吗?

Im just wondering about the best practise to do this in objective c?

例如,我是否有一个纯文本文件,其中包含所有值,然后在运行时将其读取?

For example, would I have a plain text file that contains all the values and then read it in at run time?

还是我需要创建一个包含所有这些值的对象?

Or would I need to create an object which holds all these values?

我希望它不使用网络资源,因为我希望应用程序可以脱机运行。

I would prefer this to not use a web source as I want the app to be able to run offline.

推荐答案

一百条记录,每个记录可能有几十个字段,但它们并不是很多数据。我建议将数据存储为属性列表,可能是字典数组。这是最简单的解决方案,可能足以满足您的需求。加载数据可能很简单:

A hundred records with perhaps a few dozen fields each is not a lot of data. I'd suggest storing the data as a property list, probably an array of dictionaries. This is about the simplest solution, and probably more than adequate for your needs. Loading your data could be as simple as:

NSArray *records = [[NSArray alloc] initWithContentsOfFile:pathToFile];

数组中的每个条目可以是一个字典,其中包含记录中每个字段的键。这给您很大的灵活性。当然,您可以单独访问每个记录,但是也可以使用NSPredicate来选择与指定条件匹配的记录子集。您还可以对数组使用键值编码,以获取特定键的所有值的数组。例如,如果您想为每个记录使用名称字段的数组,则可以说:

Each entry in the array could be a dictionary with a key for each field in the record. This gives you a lot of flexibility. You can of course access each record individually, but you can also use NSPredicate to pick out subsets of the records that match criteria you specify. You can also use key-value coding with the array to get an array of all the values for a particular key. For example, if you want an array of the "name" field for each record, you could say:

NSArray *names = [records valueForKey:@"name"];

SQLite和Core Data之类的解决方案有一个地方,但您可能不需要它们一个小的数据集。

There's a place for solutions like SQLite and Core Data, but you probably won't need them for such a small data set.

这篇关于在Objective-C中存储和加载大量数据的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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