将数据存储在 plist 或 Sqlite 数据库中更好吗?
在我的 iPhone 应用程序中,我有大量数据,即大约 1000 页文本。
我应该在哪里存放它们?
我应该使用 plist 还是 Sqlite 数据库表?
其中哪一个会被证明更有效率?
请帮助和建议。
提前致谢。
In my iPhone app, I have large amount of data i.e. around 1000 pages of text.
Where should I do to store them?
Should I use plist or Sqlite Database table?
Which of them would prove to be more efficient?
Please Help and Suggest.
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于大量数据,sqlite 或 coreData 更好,因为所有数据都不会加载到内存中来访问。
使用pList,整个文件被读取到内存中。之后,您可以只保留您想要的数据,但它并没有被优化。
For big amount of data, sqlite or coreData are better because all data are not load in memory to access to one.
With pList, entire file is read in memory. After, you can retain only data what you want, but it is not optimized.
取决于您想要存储数据的方式和目的:
在以下情况下使用 SQLite:
否则请使用 plist!
对于你的情况,我建议使用 SQLite 3 或 coredata。
Depends on how and for what you want to store the data:
Use SQLite if:
Use plist otherwise!!
In your case, I would reccomend, using SQLite 3 or coredata.
您应该使用 plist 来存储配置设置。
对于你正在做的事情,我会使用 sqlite3 或核心数据存储。
You should use a plist for storing configuration settings.
For what you're doing I'd use sqlite3 or core data storage.
pList 实际上只是一个 xml 文件,因此 xml 的优点(例如人类和计算机都易于读取)和缺点(存储/检索的效率)都适用。
而 SQLite 显然可以给您带来 SQL 的好处。对于大数据 SQLite 将是更好的选择
pList is really just an xml file so the advantages (such is both easily readable by human and computer) and disadvantages of xml (efficiency of storage/retrieval) apply.
While SQLite gives you the benefit of SQL obviously. For large data SQLite would be the better choice
重要的是您访问它们的方式。如果您随机或小部分访问它,您可以使用像 sqlite 这样的数据库。如果您一次粗略地使用它,那么 plist 就可以了。正如 @Benoît 提到的,plist 完全加载到内存中。对于像书这样的东西,您还可以考虑将页面存储在单独的文件中,从而使用文件系统来管理访问(当然取决于您打算如何使用它)。
What's important is the way you'll be accessing them. If it's something you access randomly or in small portions, you'd use a database like sqlite. If it's something you are using all of rougly at once, a plist is fine. As @Benoît mentioned, plists are loaded into memory completely. For something like a book you might also consider storing pages in separate files, thereby using the file system to manage access (depending on how you intend to use it of course).
属性列表
plist 只是一个嵌套键值对的列表,其中可以包含常见的数据类型,如字符串、数字、数组和字典。
优点
缺点
无法对它们运行复杂的查询(至少不容易)。
您必须将整个文件读入内存才能从中获取任何数据,并保存整个文件才能修改其中的任何内容。
SQLite
在 CoreData 出现之前,这是在 iPhone 应用程序中读写数据的流行方式。如果您是一名网络开发人员,这并不是什么新鲜事。
优点
这使得 SQLite 更适合具有大量数据的应用程序。
缺点
学习曲线比 plist 陡峭。
工作起来可能会很乏味。
核心数据
它是新的、令人兴奋的,并且可能是大多数开发人员从现在开始使用的。
我还没有在 CoreData 上花费足够的时间来总结它;查看教程(如下)以了解更多信息。
优点
几乎拥有 SQLite 的所有优点,而且麻烦更少(Apple 确实这样做)
为你省去很多脏活)。
作为Apple的首选方法,它有更多的官方文档和示例代码(似乎其他两种方法的文章和示例代码已经从Apple的网站上神秘地消失了)。
缺点
Property Lists
A plist is simply a list of nested key-value pairs which can contain common data types like Strings, Numbers, Arrays and Dictionaries.
Pros
Cons
Cannot run complex queries on them (at least not easily).
You have to read the entire file into memory to get any data out of it and save the entire file to modify anything in it.
SQLite
Until CoreData came along, this was the popular way to read and write data in iPhone applications. If your a web developer, this ain’t nothing new.
Pros
This makes SQLite more suitable for applications with lots of data.
Cons
Steeper learning curve than plists.
Can get tedious to work with.
Core Data
Its new, its exciting, and its probably what most developers will use from here on out.
I have not spent enough time with CoreData to summarize it; check out the tutorials (below) to learn more about it.
Pros
Nearly all the benefits of SQLite with a lot less hassle (Apple does
a lot of the dirty work for you).
As Apple’s preferred method it has a lot more official documentation and sample code (it seems the articles and sample code for the other two methods have mysteriously disappeared from Apple’s website).
Cons