I’m using a sqlite3 database to store app’s data. Instead of building a database within program, I introduced an existing db file: ‘abc.sqlite’ into my project and put it under my ‘Resources’ folder.
So, I think this db file should be inside of ‘bundle’, so at my init function, I used following statement to read it out:
NSString *path = [[NSBundle mainBundle] pathForResource:@"abc" ofType:"sqlite"];
if(sqlite3_open([path UTF8String], &database) != SQLITE_OK)
...
It’s ok that this db can be opened and data can be retrieved from it.
BUT, someone told me that it’s better to copy this db file into user folder: such as ‘Document’. So, my question is: is it ok to use this db from main bundle directly or copy it to user folder then use that copy. Which is better?
Thank you very much!
You should use it from your bundle if you only require readonly access. If you need to write to the file, you need to move it somewhere writable like the documents directory.
Also, as Sixten Otto notes, the Application Support directory is preferable to the Documents directory in newer SDKs.