0

Hi I am a newbie to iPhone programming. I have been looking at some tutorials online for using SQLite on the iPhone. From what Iv'e seen, one has to read the entire database in the app delegate method and then store the contents in an array. This is then used to populate a UITableView.

I was wondering how this can be efficient? I mean, if you are going to store the contents of your entire database in memory why have a database?

Is this standard practice?

Instead of this, if I use Core Data, I can set the paging size and it will optimize how much data is stored in memory and only read whats being shown within the visible cells.

Is there anyway, In can have the same functionality using SQLite? so its easy on memory. I mean my database has only 300 entries now, but what if in the future it has 3 million?

Can some one please assist me in understanding this....

Are there any tutorials for SQLite that show how to do it in an optimized way?

Thanks

MPelletier
  • 16,256
  • 15
  • 86
  • 137
banditKing
  • 9,405
  • 28
  • 100
  • 157

2 Answers2

0

I would suggest using Core Data. It's extremely powerful, better supported than a SQLite table, and not as complicated as it looks, it just uses a lot of "managed object" jargon which can be daunting at first. Check out the CoreDataHelper class, and a few tutorials. I was able to get Core Data working in a few days (in my first ever app) using the links in my comment

If you're familiar with SQL, basically Core Data works like this: the Persistent Store IS a SQLite table, but you never access it directly; the managedObjectContext is where you do all the data work in your program (and don't forget to save it to the persistent store!), while an Entity is a table, attributes of that entity are your columns, and a managed object is a row.

Further Reading:

Rembrandt Q. Einstein
  • 1,101
  • 10
  • 23
  • Thank you, everyone. However, I running into the problem that I have a prepopulated sqlite database that Id like to ship with the app. How can I do this in core-data? – banditKing Jan 10 '12 at 20:21
  • You can definitely pre-populate your app using Core Data, [this](http://stackoverflow.com/questions/2230354/any-way-to-pre-populate-core-data) seems like a good place to start – Rembrandt Q. Einstein Jan 10 '12 at 20:29
  • Thanks a lot. This got me started. – banditKing Jan 10 '12 at 21:30
-1

Here is some tutorial that may help you: iPhone Programming Tutorial.

I recommend you consider using core data instead of sqlite.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alejandro Rangel
  • 1,670
  • 1
  • 20
  • 35
  • Thank you, everyone. However, I running into the problem that I have a prepopulated sqlite database that Id like to ship with the app. How can I do this in core-data? – banditKing Jan 10 '12 at 20:21
  • i guess thad you can... heres a tutorial http://www.raywenderlich.com/980/core-data-tutorial-how-to-preloadimport-existing-data – Alejandro Rangel Jan 10 '12 at 20:33