Reputation: 1488
I have a bunch of data that I want to store in a Core Data file. The problem is that It only gets created at runtime. How can I create it before, save it into my bundle, and then display it to the user?
Upvotes: 0
Views: 63
Reputation: 3791
My preference is to use a property list (.plist) file that contains arrays and dictionaries of the "default data" I wish to preload, then on first run load that default data in.
I use code in my core data stack to check the plist file against existing default data and, in the case that I have updated the plist file with some additional default data (for subsequent production release), this is added.
I also use code in my core data stack to change or delete default data as necessary, but this is data specific.
Upvotes: 1
Reputation: 31016
I do this by running my app (or a utility written just for this purpose) in the simulator during development and populating it with its pre-set information. I then find the file on disk, put it in my project, and make sure it is included in the "Copy files" build phase.
At start up, I look for the file in the app bundle, and copy it to where CoreData expects it...that is, some writable location.
Upvotes: 2