Search code examples
iosiphonecore-datastore

What is best way to store long term data in iPhone Core Data or SQLite?


I am working on iPhone app targeting 3.1.3 and later SDK. I want to know the best way to store user's long term data on iphone without losing performance, consistency and security.

I know, that I can use Core Data, PList and SQL-Lite for storing user specific data in custom formats.But, want to know which one is good to use without compromising app performance and scalability in near future.


Solution

  • It depends. The term "user data" covers a wide scale in size, complexity and usage each of which have different optimal storage strategies.

    (1) If size and complexity are low and the usage is primarily controlling the app itself, store the data in the user defaults using NSUserDefaults.

    (2) If the size is small and the complexity can be managed by arrays, dictionaries etc then store in a plist. Size counts because all the data stored in a plist is loaded into memory in one chunk.

    (3) If the size is very large but the complexity is low e.g. a large number of template records such as an index card system, then use direct SQL. SQL is faster for finding and saving simple and repetitive information in a very large DB.

    (4) If the complexity is very high, use Core Data regardless of size. Core Data is specifically designed to manage complex information. If the size is small, use an xml store. If it is large, use a SQL store.

    As I gained familiarity with Core Data, I find myself using it for almost everything except user defaults. It has a steep learning curve but once you master it, you have a powerful and easy to use tool for managing application data. I probably use it in situations where it is not optimal just because it speeds development time.