iPhone SDK:保存大量文本

发布于 2024-08-04 07:01:33 字数 83 浏览 2 评论 0原文

我想保存大量文本然后显示它们(首先在表视图中,然后在文本视图中),但是我不确定使用哪种方法来执行此操作。我应该使用 SQLite 还是其中一种归档方法。

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.

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

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

发布评论

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

评论(2

淡淡的优雅 2024-08-11 07:01:33

您的“大量文字”表述含糊不清。您可以指以下任何一项:

  • 一大组(例如 10,000 个项目)小文本(例如 30 个单词)项目
  • 一小组(例如 50 个项目)大文本(例如 3,000 个单词)项目
  • 一大组大文本项目。 ..

我将尝试回答每种情况。

如果您要存储大量记录,我发现数据库总是一个好主意。这意味着使用 SQLite 或 CoreData。 CoreData 需要做更多的工作,但是有很多例子,从长远来看,这种方法将会得到回报。

大量数据需要数据库的主要原因是您不需要一次加载全部数据。您不希望您的用户在您的应用程序加载其所有记录时等待 30 秒(即使假设所有记录都能够加载到内存中 - 速度很快!)。 CoreData 特别设计用于这种“仅加载用户需要查看的数据”模型。

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

希望有帮助!

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

  • A large set (eg 10,000 items) of small text (eg 30 words) items
  • A small set (eg 50 items) of large text (eg 3,000 words) items
  • A large set of large text items...

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

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.

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.

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.

Hope that helps!

疯了 2024-08-11 07:01:33

我想说,如果您的文本/数据只有几千字节,那么请采用归档方法,否则 sqlite 就适合您。
祝你好运。

I would say if your text/data is just few kilo bytes, then go for archiving methods, otherwise sqlite is there for you.
Good luck.

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