开发者

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 s开发者_JAVA百科aved with NSUserDefaults? 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. SQLite is a data store with a SQL interface, so you can query it. If you structure your data, this offers some obvious benefits.

If you simply need persistent storage, consider -[NSArray writeToFile:atomically:].


Storing 1000 strings in NSUserDefaults as an array is no big deal. One advantage that using SQL Lite will give you is the ability to index your collection for fast searches. And of course that benefit just keeps on growing as your data collection increases in size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜