Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use CoreData or SQLite on iPhone? [closed]

Since CoreData has become available for the iPhone in OS 3.0, is it meant to be the answer to data persistence and replace all need for direct SQLite?

What reasons exist to still use SQLite? What are advantages/disadvantages of SQLite vs. CoreData?

like image 992
Hauke Avatar asked Aug 23 '09 12:08

Hauke


People also ask

What is the difference between Core Data and SQLite?

The short answer is simple. Core Data is a framework for managing an object graph. SQLite is a relational database. Continue reading if you are interested in the long answer.

Is Core Data equal to SQLite?

SQLite is a database while Core Data is not. Core Data is a framework for managing an object graph. Core Data is fast in terms of operation.

Should I use Core Data?

The next time you need to store data, you should have a better idea of your options. Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.

When should you not use SQLite?

A good rule of thumb is to avoid using SQLite in situations where the same database will be accessed directly (without an intervening application server) and simultaneously from many computers over a network. SQLite will normally work fine as the database backend to a website.


2 Answers

This is a common question here:

  • "Core Data vs. SQLite for SQL experienced developers"
  • "Core Data vs Sqlite and performance…"
  • "Core Data vs sqlite3"
  • "is it worth using core data for a simple sqlite app on the iphone with one table and no relationships or complicated subtable/views?"

In summary, Core Data can greatly simplify your code, particularly for complex object models. You get undo / redo support almost for free with it. It also provides some very significant performance benefits, particularly on the iPhone. Even though it seems counterintuitive, given how much overhead you'd think the framework has, in most cases you can beat the performance of hand-tuned SQLite using Core Data. On the iPhone, it does a great job of batching fetches to minimize memory usage.

The one downside, as pointed out, is that this limits you by requiring iPhone OS 3.0 for your end users. However, this has not been a problem at all for my users, and will only become less of one going forward.

like image 174
Brad Larson Avatar answered Oct 04 '22 02:10

Brad Larson


This might be a lesser benefit, but SQLite is a lot more portable between platforms, since Core Data is part of Cocoa, and SQLite is pure C. This means that if you wanted to port your application to PC, for instance, you would have less code to rewrite in the event that you use pure SQLite.

Then if you wanted to develop anything else cross-platform using a local DB (not necessarily related to any iPhone apps), you would have already have some experience with SQLite.

like image 38
Mark Rushakoff Avatar answered Oct 04 '22 04:10

Mark Rushakoff