iPhone SDK: saving large amounts of text

♀尐吖头ヾ 提交于 2019-12-11 19:59:28

问题


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.


回答1:


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!




回答2:


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.



来源:https://stackoverflow.com/questions/1391077/iphone-sdk-saving-large-amounts-of-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!