I am working with updation of database in a project in which the database found in mainBundle needs to be updated. as we already know that files in mainbundle are read only i copied the database in the mainBundle to the document directory for updation . After updation i want to replace that file in document directory to the file in mainBundle.
Can anyone please tell me how to solve this issue.
Thanks in advance
I am working with updation of database in a project in which the database
Share
That can not be done. As you cannot update any of your bundle file. Somehow if you do that your build will show a invalid binary message on next run.
By the way why you need to update the DB from your main bundle? Your mainbundle database file is a copy of your original database and that should be copied in document directory for modifying it.
UPDATE
For the case you want to persist your record even after restarting the app thats why we use database. For solving your issue do follwoing:
This will return path for your document directory. After that copy your database to this path as follows:
This will check if database is already exist at path than it won’t replace it with empty database and if database is not exist (i.e your first run of app) it will copy.
Now you can access
dbPathfor accessing database which is in you document directory and will be persistent even after restarting app.Don’t forgot to check your database existance with
if (![[NSFileManager defaultManager] fileExistsAtPath:dbPath]) {otherwise your app will replace your document directory’s db with original (empty database) on every run.Hope this help.