![]() | Pre-populating a Core Data Application. |
|
08 Apr 2009, 21:50
Felipe Laso (104 posts) |
Hello. I currently have an application that lists food ingredients and the amount of proteins each one has. I used a .plist file to load the data whenever the application is launched. The thing is I now want to write a new version that allows the user to add or remove their own food ingredients. BUT, I have not found any articles in the documentation or on the internet that suggest how to pre populate a Core Data application. Now I know there is SQLite, but Core Data seems much simpler and easier to implement in my case. Basically in SQLite I could just add the existing database file with tables and data into it, then when the application is loaded and run for the first time it will contain the data in my SQLite database. Is there a way to do this in Core Data? Either via commands or through a graphical user interface? If there is no easy way to do this, and I have to programmatically create my NSDictionary with the food ingredients, then store it with Core Data the first time my app is launched, then I’m afraid I might have to revert to using SQLite for this (which im trying to avoid since it seems rather complicated and I don’t know much SQLite). Thanks in advance, |
|
10 Apr 2009, 15:42
Marcus S. Zarra (239 posts) |
This is discussed in the book but I don’t think the chapter in question is available yet. However it is fairly simple. You have several options and the easiest is to store a copy of the database in your application with the data pre-populated. When the user wants to create a new document you copy that database over instead of creating a new one. |
|
20 Apr 2009, 00:07
Jericho Hasselbush (3 posts) |
Hi Felipe,
|
|
16 Jun 2009, 08:40
Bala Paranj (19 posts) |
I followed the blog post of Marcus that shows you how to import data in a CSV file into a Core Data application. Now I want to export this data into a new project where I need it as seed data. How can I do this? I just purchased the ebook, I have not received the link to the download yet. TIA. |
|
27 Jul 2009, 05:55
Marcus S. Zarra (239 posts) |
There is nothing to export if you want to keep it in a Core Data repository. Just grab the saved repository file and include it as a resource in the new project. I believe this same answer was given to you on the MDN blog post. |
|
30 Oct 2010, 17:15
Matt Di Pasquale (1 post) |
I Googled and found out from this post that CoreDataBooks does this. Scroll down to the persistantManagedStore function. It’s the best implementation I’ve seen. Basically, it checks to see if the SQL file already exists. If not, it copies a default one from the Resources directory there. This default file can be pre-populated however you’d like. |
| You must be logged in to comment |

