views:

909

answers:

3

Hello all,

i am working on an application that displays read-only data i am shipping. it is more of a book.

It is easy with SQLite but i am not satisfied with the performance and trying to use Core Data.

The issue is with pre-filling Core Data is that it is a hard process.

My question is: Is it possible to build an assistant iphone application (for me to use) which uses the same data model for pre-filling. and then take the populated .xcdatamodel file and use it in my original application?

I hope this makes sense :)

Adham

+2  A: 

I believe what you're asking is whether you can create a CoreData database upfront and copy it to the iPhone. Is that correct?

This article will help. Here's a quote:

I thus suggest the following five-step process:

  1. Create your data in a comma-separated file, typically placing each row of data (an entity) in a row of the file and separating different columns (its attributes) by commas.
  2. Write a standalone program and copy in your .xcdatamodel file from your main project.
  3. Write code in your new program that parses your comma-separated file and inserts the information into a Core Data persistent store that should be identical to the persistent store in your main project.
  4. Run the program in the Simulator
  5. Copy your data from the Simulator's documents directory into your actual project's bundle.
Benjamin Cox
Hi Benjamini have already read this page.My question is:can i use a stand alone program that is dedicated to filling CoreData database and after i enter the data, i copy the populated data file from the documents directory to my main bundle..to rephrase:can i replace the CVS file step with a standalone application for entering data?
Adhamox
Sure. Just eliminate step 1. Then replace step 3 with screens that allow you to insert the information yourself, rather than parsing any file for the data. The Core Data file is the essence of it, and as long as your .xcodedatamodel file is identical between the projects you can copy the file and it will work.
Benjamin Cox
thanks :) this is helpful
Adhamox
+3  A: 

It's possible, I've done it. I made a desktop application to read from a CSV file using the code here:

http://www.mac-developer-network.com/columns/coredata/may2009/

I just had to alter the way the CSV part worked, and change the model.

  • I copied and pasted my model from the model builder into the iPhone model. (Clicked on the "grid" area, selected all, copied)
  • Then I took the sqlite database the desktop app produced (found it in Application Support, in the folder for this application) and put it into the resources folder
  • I made some code to copy the sqlite into the documents folder on the iPhone (if it wasn't already there) at startup, in the applicationDidLaunch method. It's possible that having it in the resources folder is no good. Even though you're using the database as read only, Core Data may want to write something to it. Not sure about this though..
  • I used the sqlite file in the documents folder in my Core Data set up.

The desktop and iPhone Core Data sqlite file seem to be exactly the same format. You can transfer one sqlite file to another application (iPhone to iPhone too) as long as they have the same data model. In another application, I used NSXMLParser to create the Core Data sqlite file, then transferred it to another app, both on iPhone using the Simulator.

nevan
thank you too nevan.. this solution is a bit complicated for me as i am a newbie but you made the concept clear.
Adhamox