4

I'm new to iOS programming.

I want to know how a database is created on a real iPhone device for the first time.

I have created a database from the terminal and copied it to the project directory and used it for insert/update/delete/etc as shown in many of the tutorials. But how will it be created when I run the app on a real device?

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
The_code_cracker
  • 159
  • 2
  • 13

3 Answers3

4

Use Core Data to simplify your database access needs in iOS. It is backed by a SQLite DB by default and will create one if there isn't any yet.

If you need to pre-populate the DB, then make one like you mention in your question, and add it as a resource in your Xcode project. Then when your app starts for the first time, before initializing core data, copy your .sqlite file into the Documents folder and it will be used.

mprivat
  • 21,582
  • 4
  • 54
  • 64
2

you can use core data as well as sqlite .

when you add sqlite file in you application, and run it in device , then sqlite file will automatically saved to document directory .

you can find that file for simulator in :

/Users/URNAME/Library/Application Support/iPhone Simulator/4.3/Applications/1B787527-0608-4BC1-8022-DFDB3CC35F66/mysqlite.sqlite.

For more detail see

How to get Sqlite database file when application is running on device

For Add sqlite in your app see

http://www.icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-1/

Community
  • 1
  • 1
PJR
  • 13,052
  • 13
  • 64
  • 104
0

You can use following two options,

  • Using core data

  • Using direct SQLite

Ref Link: When to use Core Data and when to use Sqlite?

Community
  • 1
  • 1
ABC1
  • 116
  • 7