views:

484

answers:

4

I'm trying create 2 apps, one that builds a persistent store, and another one that consumes it.

So far I have built one app that uses CoreData to successfully build a database from an XML file. So this project contains the data model, the .h/.m files for the entities, etc.

I'm now trying to enable the second app to read that .sqlite file by copying the data model file, the .h/.m files related to the entities and the sqlite file to that project (via add existing).

The code executes but always fails to find any objects in the database.

Are there any restrictions or correct steps to take when trying to copy over these files?

A: 

I think (not 100 percent sure) in your app plist, if you set your application bundle name to the same thing, they will share resources because the device will think they are the same application...

Daniel
A: 

I don't think this is going to work the way that you want it to. On the iPhone, each application runs in its own "sandbox", and it's not really possible for one application to write files that another can read.

Mark Bessey
But i believe if they have the same bundle path, they will share resources
Daniel
But they are considered the same application
Daniel
Actually, I should have been more clear in my original post. What I'm trying to do is run one app in simulator to create a database (persistent store) out of a whole lot of XML files. Then, copy over data model + database and entity related .m/.h files, to the actual application that will mostly just read that database. So once on the actual device, I'm just working within the second app. Does that make sense?Thanks for the help!
rhess
A: 

Is it really two different projects, or is it two targets in the same project? That would seem to make a lot more sense, and then you can share entity objects as they change.

Kendall Helmstetter Gelner
Currently I really have them as 2 different projects. one is the 'Data Store Creator' that loads entities from XML into a persistent SQLite store, the other the actual app.
rhess
A: 

The solution here is deceptively simple.

Just copy your .xcdatamodel file from one project to another and then when you run your app in the simulator for the first time it'll create a Documents folder for the app. Just drop your saved .sqlite or .binary files into the yourApp/Documents directory on the device. You can find the simulator directory in "~user/Library/Application Support/iPhone Simulator".

You can also download, edit, and upload the myApp directory on a provisioned iPhone by dragging and dropping into and out of the Organizer. Look at the Applications list.

The iPhone doesn't support xml stores with core data, only sqlite or atomic (binary). The sqlite store is by far the better option for most applications since it doesn't all have to be loaded into memory at runtime.

Is this what you meant?

pingbat