简体   繁体   English

为什么在NSArray上使用SQLite

[英]Why use SQLite over NSArray

Is there a reason to store, let's say, about a thousand strings with a SQLite database over a NSArray saved with NSUserDefaults? 假设有理由在用NSUserDefaults保存的NSArray上用SQLite数据库存储大约一千个字符串? What is the advantage to having a database? 建立数据库有什么好处? Thanks for your help! 谢谢你的帮助!

It depends what the strings are and how they will be accessed. 这取决于字符串是什么以及如何访问它们。 Databases offer sophisticated querying and relational storage capabilities. 数据库提供了完善的查询和关系存储功能。 Do you need to query it? 您需要查询吗? Will the complexity of the data grow over time? 数据的复杂性会随着时间增长吗?

Also, as the number of strings grow, you'll be writing thousands of strings to add one since it's overwriting the full array. 另外,随着字符串数量的增加,您将编写成千上万个字符串以添加一个,因为它会覆盖整个数组。

NSUserDefaults probably isn't the best option for storing so much data. NSUserDefaults可能不是存储大量数据的最佳选择。 SQLite is a data store with a SQL interface, so you can query it. SQLite是具有SQL接口的数据存储,因此您可以对其进行查询。 If you structure your data, this offers some obvious benefits. 如果您构建数据,这将带来一些明显的好处。

If you simply need persistent storage, consider -[NSArray writeToFile:atomically:] . 如果仅需要持久性存储,请考虑-[NSArray writeToFile:atomically:]

Storing 1000 strings in NSUserDefaults as an array is no big deal. 在NSUserDefaults中将1000个字符串存储为数组没什么大不了的。 One advantage that using SQL Lite will give you is the ability to index your collection for fast searches. 使用SQL Lite可以为您带来的好处之一就是可以为快速搜索而索引您的集合。 And of course that benefit just keeps on growing as your data collection increases in size. 当然,随着数据收集规模的增加,这种好处只会不断增长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM