4

The answer is probably a resounding 'NO' but before I start a new project from scratch, I thought I'd ask.

I create many throw away projects to test ideas and code before combining all the successful bits from the scratch projects into a final version. So I have one project with the Core Data stuff worked out but I want to move it to a new project. My guess is that there is too many internal hooks and dropping in the .xcdatamodel and the sqlite db is just not going to work.

I'd glad to be wrong...

Michael Morrison
  • 1,323
  • 1
  • 18
  • 30

3 Answers3

1

I tried this on a couple of projects and what I found is that in one of the sqlite tables is an entry for the build number. Deleting that entry solve the migration problem for me. Prior to that I was getting the same errors, especially one that the Persistent Store could not be created.

  • I've just tested that and works! Just deleted the only record in table Z_METADATA and can transfer one .sqlite file created using Core Data from one target to another. I've used the [SQLite Database Browser](http://sqlitebrowser.sourceforge.net/) that's Open source – Diego Freniche Mar 26 '12 at 06:50
0

Old question but I came across this myself trying to solve the same question! Michael ... I work like you and was very frustrated that I couldn't figure out how to move code data models around into different projects. My solution ended up being doh! stupid. You can ...

Cut and paste the core data entities from project to project using command-c and command-v

Ouch. I had a project that loaded the data model from a .csv file ... so I didn't need the data to come along with the data model. I hope that helps!

I imagine that once the data model is the same you could move over the .sqllite file just fine but I haven't tried that. I hope that helps.

0

You should be able to do it. Just make sure you name everything correctly when referencing it. I actually have a project right now which uses the exact same data model for the OS X and iOS versions.

ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123
  • So just move the .xcdatamodel, .sqlite and some managedObject class files over and of course modify the code that references the persistent store and that should do it? - Sounds too good to be true. I'll try it. - Thanks – Michael Morrison Jan 18 '11 at 02:09
  • Hmmm ... it almost worked for me. I am crashing XCode (Ver 4.x) and when I do get the code to run, it traps with "2011-07-27 17:05:56.352 Mobile MPVI[1650:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model' ." I am not able to track down my model is not getting allocated -- the code is there :) – mobibob Jul 27 '11 at 21:17
  • @mobibob The most likely reason the model is nil is that it couldn't be found. Make sure the URL you are using is correct and it is getting added to the bundle properly at build time. – ughoavgfhw Jul 27 '11 at 21:31
  • @ughoavgfhw I think it was just a weakness in copy-n-paste from my study project to my final project. I ended up just deleting out the files manually and re-creating the model by hand. It was not too painful since the model is small, but I hope I can copy larger models in to my projects in the future without foo-barring my code. – mobibob Jul 28 '11 at 14:31