I’ve created a default iOS application in Xcode with Core Data. I’ve placed a default myDatabase.sqllite file in my project, which I would like to use the first time the application starts — so every user does not have to fetch all new items.
How can I change the code in the AppDelegate.m to use my default myDatabase.sqllite first time the application starts?
I normally create my persistant store and pre-seed it in the simulator, which is nice and fast compared to on the device especially if data is coming from the network or XML. I then copy the output (.sqlite) of that file into the project bundle.
Then when you start the app do a check and if the database does not exist in the place where the persistant store coordinator looks then copy your pre-seeded database from your bundle into the correct place.
I believe this is what the documentation @simon talks about is referring to when it says create a separate persistant store and copy it into place.
Updated
Take a look at NSFileManager it has the following method
due to the previous fact you can probably get away with just using that method and not trying to do any
which cold potentially lead to race conditions.
Therefore before your
NSPersistentStoreCoordinatoris loaded you need to do something like: