Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

cocoa touch - Add an SQLite database to an iPhone app

I am trying to learn SQLite, and I am building an iPhone app. But I would like to add an SQLite database to my building app. I have got three tutorials, but I am not clear on that code.

How can I add an SQLite database to my building app? What would sample code look like?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First of all you need to create your database.
From the command line create your db file.

sqlite3 mydb.db

Then create the tables within your database

CREATE TABLE tags (id int(5), name varchar(255), created_at datetime, updated_at datetime);

Repeat that for any tables that you want in your database.

Then you need to include the database file in your project. Add the existing database file to your project as you would any other existing file.

Next you will have to link in the framework to interact with the database. This can be found under you current iPhone SDK folder.

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/lib/libsqlite3.0.dylib

Finally you have to include the header file sqlite3.h from

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/include/sqlite3.h

It should now be possible to write code to access your sqlite database from within your iPhone application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...