iPhone SDK:保存大量文本 [英] iPhone SDK: saving large amounts of text

查看:84
本文介绍了iPhone SDK:保存大量文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存大量文本然后显示它们(首先在表格视图中,然后在文本视图中显示),但是我不确定该使用哪种方法.我应该使用SQLite还是一种归档方法./p>

I want to save large amounts of text then display them (first in table view, then in text view), however I am unsure which method to do it in. Should I use SQLite, or one of the archiving methods.

推荐答案

您对大量文本"的陈述不明确.您可能表示以下任何一种情况:

Your statement of "large amounts of text" is ambiguous. You could mean any of the following:

  • 一大套(例如10,000个项目)小文本(例如30个单词)项目
  • 少量(例如50个项目)的大文本(例如3,000个单词)项目
  • 大量的大型文本项...

在每种情况下,我都会尝试回答.

I'll try and answer for each of those scenarios.

如果要存储大量记录,我发现数据库总是一个好主意.这意味着使用SQLite或CoreData. CoreData还有很多工作要做,但是周围有很多例子,从长远来看,这种方法将会奏效.

If you're storing a large number of records, I find a database is always a good idea. This means using either SQLite or CoreData. CoreData is a bit more work to get going but there are plenty of examples around and this approach will pay off in the long run.

对于大型数据集而言,需要数据库的主要原因是您不需要一次全部加载数据库.您不希望用户在应用加载所有记录的同时闲坐30秒钟(即使假设所有应用都可以加载到内存中-快速运行!).特别是CoreData旨在与这种仅加载用户需要查看的数据"模型一起使用.

The main reason a database is required for large sets of data is that you then don't need to load it all at once. You don't want your users sitting around for 30 seconds while your app loads up all its records (even assuming it will all be able to load into memory - it goes quickly!). CoreData in particular is designed to work with this "load just the data the user needs to see" model.

但是,如果您的数据量很小,即使每个项目都相对较大,也不太可能通过将它们放入数据库来获得很多收益.如果您认为将来的数据量可能会增加,那是值得的.但是,如果它永远不会增长,那么您可能可以摆脱归档-甚至可能是所有机制中最简单的一种,将数组或字典直接粘贴到plist中.这是最快的实现方法,但是如上所述,在许多情况下肯定是个坏主意.

However if you have a small set of data, even if each item is relatively large, you're unlikely to gain much by putting them into a database. If you think the quantity of data could grow in the future, it's worth doing it. But if it's likely to never grow you can probably get away with archiving - and possibly even the easiest of all the mechanisms, sticking an array or dictionary straight into a plist. This is the quickest way to implement but as described above certainly is a bad idea in a number of situations.

希望有帮助!

这篇关于iPhone SDK:保存大量文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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