ericlvb
ericlvb

Reputation: 89

Data storage for an iPhone application

I am writing an application that has all the buildings on my campus and in a tableview. When you click a building it will retrieve info on it such as the longitude, latitude, building name, and an image of it.

My question is what do you think is the best way to store this data? Should I used sqlite3 database or maybe Core Data? Sqlite3 is what I am leaning towards right now, I'm somewhat familiar with SQL. Any suggestions would be appreciated.

Upvotes: 1

Views: 375

Answers (2)

ericlvb
ericlvb

Reputation: 89

OK, so i figured out a great way to do this using Core Data. I created the Core Data model with an entity and its attributes. The entity and its attributes correspond to a table and its columns. I ran it and it created an empty sqlite file. You can find this file in:

/Users/[name]/Library/Application Support/iPhone Simulator/5.0/Applications/[some long HEX number]/Documents

from there, you can open and view the sqlite file and its contents by typing:

> sqlite3 [name of file].sqlite
> .schema

.schema shows the tables and columns. You notice that when Core Data creates a sqlite database, it will call the table Z[entity] and the columns Z[attribute] where entity is the name of your entity and attribute is the name of your attribute. So the table and all the attributes have a Z preceding it.

I then wrote a script to gather all the information and store it in this database which I then put back in the directory I found it from and it worked! Hope this helps someone who runs into the same problem I did.

I definitely suggest using Core Data over SQLite, Core Data is much easier to use.

UPDATE: I should mention that I used this to initialize a database and not make any changes to it after the initialization.

Upvotes: -2

Sergio Moura
Sergio Moura

Reputation: 4942

CoreData uses SQlite. If you're into learning, that would be your best bet, since all apple-related things (iphone, ipad, ipod touch and MacOS X all have support to it).

There are lots of books and examples on how to use CoreData. Also, CoreData can handle updates do your database in a nice way.

To use CoreData, you don't need to write any line of SQL. Its all done for you by the API.

Upvotes: 5

Related Questions