Braun
Braun

Reputation: 13

Shipping an iOS app with a read-write enabled (also pre-filled) sqlite database

This is the first time I'm developing for iOS. I need my app to ship with a pre-filled sqlite database which a user will read from and write to. How should I go about deploying this? Can experienced developers help me?

What I thought was this: I create and pre-fill the database in my development machine, add it to my app bundle. During app initialization in device, I check if I have a database in NSDocumentDirectory of my app. If not, I copy the database in the bundle to NSDocumentDirecory and read from/write into it. If I have a db there, I just use it.

Is this a bad idea? Any pitfalls I'm falling in here?

Upvotes: 1

Views: 393

Answers (1)

AndyD273
AndyD273

Reputation: 7279

I have an app that does something pretty similar to that. Mine doesn't allow writing to the database, but I don't see why it would be hard.

I have a dataset that I import into a SQLite database, copy it into the apps directory, put the DB filename into a constant and it seems to work really well.

I change the SQLite filename each time I put it in there (MyDB62020111.sqlite -> MyDB62020112.sqlite) just to make sure that I avoid a problem where it thinks that the file is already in the NSDocumentDirectory and not update it.

Upvotes: 1

Related Questions